【发布时间】:2017-01-08 09:56:05
【问题描述】:
我需要我的单元测试来等待我们的子系统初始化,这通常需要几秒钟。为了等待这个,我可以在测试中执行以下操作
- (void)testReverseActionWithOffset
{
XCTestExpectation *expectation = [self expectationWithDescription:@"High Expectations"];
// Wait for proper initialization of Realm and CrimsonObject system...
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
问题是,使用这种技术,我必须在每一个测试方法中都等待。这导致即使在系统启动后,每次测试之间也会有两秒的延迟。因为测试方法以未确定的顺序运行,所以我不能只将延迟放在一种方法上。在 XCTest 下处理这个问题的正确方法是什么?
【问题讨论】:
标签: objective-c unit-testing testing xctest