异步性能测试与XCTest [英] Asynchronous Performance Tests with XCTest

查看:834
本文介绍了异步性能测试与XCTest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始探索异步和性能测试新XCTest的API。孤立地看,从WWMC苹果的例子很好地工作,但我一直无法弄清楚如何将它们结合起来。最好的我已经能够拿出的是下面的,但我收到以下错误运行时:

I have started to explore the new XCTest APIs for asynchronous and performance testing. In isolation, the Apple examples from WWMC work well, but I have been unable to figure out how to combine them. The best I have been able to come up with is the following, but I receive the following error when it runs:

API违规 - 呼叫只能等待,而不必设置任何期望。

API violation - call made to wait without any expectations having been set.

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

任何人都已经能够完成类似的东西?

Has anyone been able to accomplish something similar?

THX

推荐答案

通过从苹果一些帮助,我有一个解决方案。对我而言,因为这愚蠢的监督是很容易解决的。去工作,你需要做的就是把预期目标(clsQueryReturnedExpectation)的创建内部measureMetrics块因此被重新创建的每个性能运行测试时。

With some help from Apple, I have a solution. Silly oversight on my part as this is very easy to solve. To get to work, all you need to do is put the creating of the expectation object (clsQueryReturnedExpectation) inside the measureMetrics block so it is created afresh each time the performance test is run.

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

这篇关于异步性能测试与XCTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆