Objective c “如何在”中使用异步过程(例如登录);设置";单元测试的方法Xcode 6
我正在寻找在setup或teardown方法中使用xctextexpection的东西。在Objective-C中,它看起来像这样:Objective c “如何在”中使用异步过程(例如登录);设置";单元测试的方法Xcode 6,objective-c,xcode,unit-testing,asynchronous,xcode6,Objective C,Xcode,Unit Testing,Asynchronous,Xcode6,我正在寻找在setup或teardown方法中使用xctextexpection的东西。在Objective-C中,它看起来像这样: - (void)setUp { XCTestExpectation *getUserAsyncComplete = [self expectationWithDescription:@"Get Request Attempted and Finished"]; [Connection loginWithEmail:@"some@email.com" onSuc
- (void)setUp {
XCTestExpectation *getUserAsyncComplete = [self expectationWithDescription:@"Get Request Attempted and Finished"];
[Connection loginWithEmail:@"some@email.com" onSuccess:^void(^) {
[getUserAsyncComplete fulfill];
} onError:nil;
[self waitForExpectationsWithTimeout:[self.timeLimit doubleValue] handler:^(NSError *error) {
if (error != nil) {
XCTFail(@"Failure: user retrieval exceeded %f seconds.", [self.timeLimit doubleValue]);
}
}];
}
我试过这个代码,但它似乎不起作用;这可能是因为Xcode 6仍处于测试阶段,或者它不受支持。即使Swift中有一个解决方案,我们也会非常感激。您输入了错误的方法名称,这似乎很好(Xcode 6,beta 2)
- (void)setUp {
[super setUp];
XCTestExpectation *exp = [self expectationWithDescription:@"Login"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(29 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[exp fulfill];
});
[self waitForExpectationsWithTimeout:30 handler:^(NSError *error) {
// handle failure
}];
}
- (void)testExample {
XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
}