XCTestCase Objective

编程入门 行业动态 更新时间:2024-10-23 05:43:06
本文介绍了XCTestCase Objective-C的多重测试性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在测试课程中有2种性能测试方法.如果我单独运行它们,它们会通过.如果我运行Hole类方法,它们将失败,并显示以下消息:

I have 2 performance test methods in test class. If i run them separately they pass. If i run hole class methods they fail with message:

****由于未捕获的异常"NSInternalInconsistencyException"而终止应用程序,原因:违反API-多次调用-[XCTestExpectation履行]." *

**** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'API violation - multiple calls made to -[XCTestExpectation fulfill].'*

有什么方法可以将一对夫妇的性能测试包括在内吗?

Is there any way to include couple performance tests in 1 class?

这是示例代码:

- (void)testPerformanceAuthenticateWithLogin { XCTestExpectation *authenticateExpectation = [self expectationWithDescription:@"Authenticate With Login"]; __block int userID = 0; [self measureBlock:^{ [AuthenticationService authenticateWithLogin:email password:password success:^(AuthenticationResponse *result) { XCTAssert(result.isAuthenticated); userID = result.userID; [authenticateExpectation fulfill]; } failure:^(NSError *error) { XCTAssertNil(error); }]; }]; [self waitForExpectationsWithTimeout:3 handler:^(NSError *error) { XCTAssertNil(error); [AuthenticationService logoutWithServicePersonID:userID success:nil failure:nil]; }]; } - (void)testPerformanceGetServicePersonByID { XCTestExpectation *getServicePersonExpectation = [self expectationWithDescription:@"get Service Person By ID"]; __block int userID = 0; [AuthenticationService authenticateWithLogin:email password:password success:^(AuthenticationResponse *result) { userID = result.userID; [self loginSuccess:result]; [self measureBlock:^{ [ServicePersonService getServicePersonByIDWithServicePersonID:userID success:^(ServicePersonDTO *result) { XCTAssertNotNil(result); [getServicePersonExpectation fulfill]; } failure:^(NSError *error) { XCTAssertNil(error); }]; }]; } failure:^(NSError *error) { XCTAssertNil(error); }]; [self waitForExpectationsWithTimeout:3 handler:^(NSError *error) { XCTAssertNil(error); [AuthenticationService logoutWithServicePersonID:userID success:nil failure:nil]; }]; }

推荐答案

measureBlock实际上多次在块内运行代码以确定平均值.

The measureBlock actually runs the code inside the block multiple times to determine an average value.

如果我理解正确,那么您想测量认证需要多长时间.如果是这样的话:

If I understand correctly you want to measure how long does the authentication take. If that's the case:

  • 您可以将期望值放入度量值块中,以便每次执行度量值迭代时,测试迭代值将在新的执行块之前等待期望值得到满足
  • 为了以防万一,您可以提高期望超时时间.

我已经做了类似的事情(对我有用):

I've done something like this (which worked for me):

- (void)testPerformanceAuthenticateWithLogin { [self measureBlock:^{ __block int userID = 0; XCTestExpectation *authenticateExpectation = [self expectationWithDescription:@"Authenticate With Login"]; [AuthenticationService authenticateWithLogin:email password:password success:^(AuthenticationResponse *result) { XCTAssert(result.isAuthenticated); userID = result.userID; [authenticateExpectation fulfill]; } failure:^(NSError *error) { XCTAssertNil(error); }]; [self waitForExpectationsWithTimeout:10 handler:^(NSError *error) { XCTAssertNil(error); [AuthenticationService logoutWithServicePersonID:userID success:nil failure:nil]; }]; }]; }

更多推荐

XCTestCase Objective

本文发布于:2023-05-28 12:32:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/320973.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:XCTestCase   Objective

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!