我已经开始探索用于异步和性能测试的新 XCTest API。单独来看,WWMC 中的 Apple 示例运行良好,但我一直无法弄清楚如何将它们结合起来。我能想到的最好的方法如下,但运行时收到以下错误:
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
在苹果的帮助下,我找到了一个解决方案。我的愚蠢疏忽,因为这很容易解决。要开始工作,您所需要做的就是将期望对象 (clsQueryReturnedExpectation) 的创建放入measureMetrics 块中,以便每次运行性能测试时都会重新创建它。
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];
}];
}];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)