How to use asynchronous procedures (ex, login) in the "setUp" method of Xcode 6 for unit testing

I am looking for something that uses XCTextExpectation in install or uninstall methods. In Objective-C, it will look something like this:

- (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]); } }]; } 

I tried this code and it does not seem to work; or it may be due to the fact that Xcode 6 is still in beta or not supported. Even if there is a solution in Swift, it will be very useful.

+6
source share
1 answer

You mistakenly provided a method name, this seems to work fine (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__); } 
+8
source

Source: https://habr.com/ru/post/971160/


All Articles