XCTests为SLComposeViewController

我正在尝试使用XCTest for SLComposeViewController编写unit testing用例,到目前为止找不到任何解决scheme。任何有关方法和代码的build议都会有所帮助。

我的目标是使用XCTesttesting下面的代码

SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; SLComposeViewControllerCompletionHandler __block completionHandler = ^(SLComposeViewControllerResult result) { [tweetSheet dismissViewControllerAnimated:YES completion:nil]; switch(result) { case SLComposeViewControllerResultCancelled: { [self showAlertWithTitle:nil andMsg:NSLocalizedString(@"Sharing failed", @"Workout summary text")]; } break; case SLComposeViewControllerResultDone: { [self showAlertWithTitle:NSLocalizedString(@"Success", @"Success") andMsg:NSLocalizedString(@"Message shared", @"Workout summary share text")]; } break; } }; 

如果要执行asynchronoustesting,则创build一个“期望”对象,该对象设置一个期望某个asynchronous任务将在稍后时间完成的期望。 然后在你的asynchronous任务完成块中,你实现了这个期望。 最后,回到主队列中,在启动asynchronous任务之后,等待期望得到满足。

因此,把这一切放在一起,asynchronoustesting看起来像

 - (void)testSomethingAsynchronous { XCTestExpectation *expectation = [self expectationWithDescription:@"some description"]; [self doSomethingAsynchronousWithCompletionHandler:^{ // do whatever tests you want // when all done, fulfill the expectation [expectation fulfill]; }]; [self waitForExpectationsWithTimeout:30.0 handler:nil]; }