multiple testPerformance with XCTestCase objective-C

这一生的挚爱 提交于 2019-12-01 08:33:30

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:

  • you could put the expectation inside the measure block so every time a measure iteration is done, the test iteration will wait for the expectation to be fulfilled before executing the block again
  • you could bump up the expectation timeout a bit just in 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];
        }];
    }];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!