Saturday, 15 September 2012

objective c - How to have Asynchronous Procedures (e.x., login) in "setUp" method Xcode 6 for Unit Testing -



objective c - How to have Asynchronous Procedures (e.x., login) in "setUp" method Xcode 6 for Unit Testing -

i'm looking uses xctextexpectation in setup or teardown methods. in objective-c, this:

- (void)setup { xctestexpectation *getuserasynccomplete = [self expectationwithdescription:@"get request attempted , 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've tried code , doesn't seem working; either because xcode 6 still in beta, or it's not supported. if there solution in swift, appreciated.

you mistyped method name, seems 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 \"%s\"", __pretty_function__); }

objective-c xcode unit-testing asynchronous xcode6

No comments:

Post a Comment