2014-06-22 5 views
6

Sto cercando qualcosa che utilizzi XCTextExpectation nei metodi di installazione o di rimozione. In Objective-C, sarebbe simile a questa:Come disporre di procedure asincrone (e.x., accesso) nel metodo "setUp" Xcode 6 per il test delle unità

- (void)setUp { 

XCTestExpectation *getUserAsyncComplete = [self expectationWithDescription:@"Get Request Attempted and Finished"]; 

[Connection loginWithEmail:@"[email protected]" 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]); 
    } 
}]; 
} 

Ho provato questo codice e non sembra funzionare; o quello potrebbe essere perché Xcode 6 è ancora in beta, o non è supportato. Anche se ci fosse una soluzione in Swift, sarebbe molto apprezzato.

risposta

8

È sbagliato a digitare il nome del metodo, questo sembra funzionare bene (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__); 
} 
Problemi correlati