我在测试课程中有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
发布评论