2014-07-09 33 views
9

我已经开始探索用于异步和性能测试的新XCTest API。另外,来自WWMC的Apple示例运行良好,但我一直无法弄清楚如何将它们结合起来。我能够想到的最好的是以下内容,但它在运行时收到以下错误:XCTest的异步性能测试

API违例 - 呼叫等待,没有设置任何期望。

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

有没有人能够完成类似的事情?

Thx

回答

21

在Apple的帮助下,我有一个解决方案。因为这很容易解决,所以我的观点很傻。要开始工作,您只需要在measureMetrics块中创建期望对象(clsQueryReturnedExpectation),以便每次运行性能测试时重新创建它。

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

除了时间以外还有什么可以测量的吗? API参考似乎表示它需要一组XCTPerformanceMetrics,但我无法在任何地方找到任何要测量的地方。 –

+0

据我所知,不,你不能。我读过同样的东西,但认为苹果在这一点上还没有实现任何东西。 – spottedrabbit