Ios 使用XCTest进行异步性能测试

Ios 使用XCTest进行异步性能测试,ios,unit-testing,asynchronous,xctest,Ios,Unit Testing,Asynchronous,Xctest,我已经开始探索用于异步和性能测试的新XCTest API。单独来看,WWMC中的苹果示例运行良好,但我无法找出如何将它们结合起来。我能想到的最好的方法是如下,但在它运行时,我收到以下错误: API冲突-调用等待而未设置任何预期 XCTestExpectation *clsQueryReturnedExpectation = [self expectationWithDescription:@"clsQuery returned"]; PFCLSClient *theClient = [[PFC

我已经开始探索用于异步和性能测试的新XCTest API。单独来看,WWMC中的苹果示例运行良好,但我无法找出如何将它们结合起来。我能想到的最好的方法是如下,但在它运行时,我收到以下错误:

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];
   }];
}];
有人能完成类似的事情吗


在苹果公司的帮助下,我有了一个解决方案。我的疏忽是愚蠢的,因为这很容易解决。要开始工作,您所需要做的就是将期望对象(clsqueryreturnedexpection)的创建放在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];
   }];
}];

除了时间,还有什么可以衡量的吗?API参考似乎说它需要一系列XCTPerformanceMetrics,但我在任何地方都找不到任何其他可测量的东西。我也读过同样的东西,但我认为苹果目前还没有实施任何措施。