2014-07-09 18 views
9

Ho iniziato a esplorare le nuove API XCTest per i test asincroni e delle prestazioni. Isolati, gli esempi Apple di WWMC funzionano bene, ma non sono riuscito a capire come combinarli. Il meglio che ho potuto ottenere è il seguente, ma ricevo il seguente errore quando è in esecuzione:Test delle prestazioni asincrone con XCTest

Violazione API - chiamata fatta per attendere senza che alcuna aspettativa sia stata impostata.

XCTestExpectation *clsQueryReturnedExpectation = [self expectationWithDescription:@"clsQuery returned"]; 

PFCLSClient *theClient = [[PFCLSClient alloc] init]; 

[self measureMetrics:@[XCTPerformanceMetric_WallClockTime] automaticallyStartMeasuring:YES forBlock: ^{ 
    [theClient getStructureOfType:clsImageTypeSVG ForID:idString success: ^(NSDictionary *structureInfo) { 
     [clsQueryReturnedExpectation fulfill]; 
} failure: ^(NSError *error) { 
     XCTFail(); 
     [clsQueryReturnedExpectation fulfill]; 
}]; 

    [self waitForExpectationsWithTimeout:5 handler: ^(NSError *error) { 
     [self stopMeasuring]; 
    }]; 
}]; 

Qualcuno è stato in grado di realizzare qualcosa di simile?

Thx

risposta

21

Con un po 'di aiuto da parte di Apple, ho una soluzione. Silly oversight da parte mia in quanto è molto facile da risolvere. Per andare al lavoro, tutto ciò che devi fare è mettere la creazione dell'oggetto expectation (clsQueryReturnedExpectation) all'interno del blocco measureMetrics in modo che venga ricreata ogni volta che viene eseguito il test delle prestazioni.

PFCLSClient *theClient = [[PFCLSClient alloc] init]; 

[self measureMetrics:@[XCTPerformanceMetric_WallClockTime] automaticallyStartMeasuring:YES forBlock: ^{ 
    XCTestExpectation *clsQueryReturnedExpectation = [self expectationWithDescription:@"clsQuery returned"]; 
    [theClient getStructureOfType:clsImageTypeSVG ForID:idString success: ^(NSDictionary *structureInfo) { 
     [clsQueryReturnedExpectation fulfill]; 
    } failure: ^(NSError *error) { 
     XCTFail(); 
     [clsQueryReturnedExpectation fulfill]; 
    }]; 

    [self waitForExpectationsWithTimeout:5 handler: ^(NSError *error) { 
     [self stopMeasuring]; 
    }]; 
}]; 
+0

È possibile misurare qualcos'altro oltre al tempo? Il riferimento all'API sembra dire che richiede un array di XCTPerformanceMetrics ma non riesco a trovare nient'altro da misurare. –

+0

Per quanto ne so, no non puoi. Ho letto la stessa cosa ma penso che Apple non abbia implementato nulla a questo punto. – spottedrabbit

Problemi correlati