2014-07-09 23 views
9

Asenkron ve performans testleri için yeni XCTest API'lerini keşfetmeye başladım. İzolasyonda, WWMC'nin Apple örnekleri iyi çalışıyor, ancak bunları nasıl birleştireceğimi anlayamadım. Geldiğim en iyisi aşağıdakidir, ancak şu hatayı alırken aşağıdaki hatayı alıyorum:XCTest ile Asenkron Performans Testleri

API ihlali - herhangi bir beklenti olmadan beklemek için yapılan çağrı.

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

Herkes benzer bir şey başardı mı?

Apple'dan bazı yardımıyla Thx

cevap

21

, bir çözüm var. Benim üzerimde olduğu gibi aptal gözetimi çözmek çok kolay. Çalışmak için tek yapmanız gereken, ölçü testi nesnesi (clsQueryReturnedExpectation) oluşturulmasını, ölçüm testi her çalıştırıldığında yeniden oluşturulmasını sağlamaktır.

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

Zaman dışında başka bir şey ölçülebilir mi? API referansı, bir dizi XCTPerformanceMetrics aldığını söylüyor, ancak ölçülecek başka bir şey bulamıyorum. –

+0

Bildiğim kadarıyla, yapamazsın. Aynı şeyi okudum ama Apple'ın bu noktada hiçbir şey uygulamadığını düşünüyorum. – spottedrabbit