2014-07-09 2 views
9

비동기 및 성능 테스트를 위해 새로운 XCTest API를 탐색하기 시작했습니다. 이와는 별개로 WWMC의 Apple 사례는 잘 작동하지만 필자는이를 결합하는 방법을 찾아 낼 수 없었습니다. 내가 얻을 수 있었던 최선은 다음과 같습니다. 그러나 실행시 다음과 같은 오류가 발생합니다.XCTest로 비동기 성능 테스트

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

누구나 비슷한 것을 달성 할 수 있습니까?

Thx

답변

21

Apple의 도움으로 저는 해결책이 있습니다. 이 부분에 대한 어리석은 감시는 해결하기가 매우 쉽습니다. 작동 시키려면 expectMetrics 블록 내에 expectation 객체 (clsQueryReturnedExpectation)를 생성하여 성능 테스트가 실행될 때마다 새로 생성되도록해야합니다.

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

다른 시간 외에 측정 할 수있는 것이 있습니까? API 참조는 XCTPerformanceMetrics 배열을 사용하지만 측정 할 수있는 다른 위치를 찾을 수 없다고합니다. –

+0

내가 아는 한, 당신은 할 수 없습니다. 나는 똑같은 것을 읽었지 만, 애플이이 시점에서 아무 것도 구현하지 않았다고 생각한다. – spottedrabbit