我试图使用XCTest为SLComposeViewController编写单元测试用例,但找不到任何解决方案,因此far.Any在方法和代码方面的建议将会有所帮助。
我的目标是使用XCTest测试以下代码
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;
}
};发布于 2014-11-13 13:32:10
如果您想要执行异步测试,您可以创建一个“期望”对象,该对象设置了某个异步任务将在稍后的时间点完成的期望。然后,在您的异步任务完成块中,您实现了该期望。最后,回到主队列中,在启动异步任务后,等待该期望的实现。
因此,将所有这些放在一起,异步测试将如下所示
- (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];
}https://stackoverflow.com/questions/26901797
复制相似问题