2

我正在尝试为 API 请求方法编写性能测试。当我在没有 measureBlock 的情况下运行它时,它运行正常,但是当我将它用作性能测试时,我收到了错误消息:

*** -[Performance waitForExpectationsWithTimeout:handler:] 中的断言失败,/SourceCache/XCTest_Sim/XCTest-7701/XCTestFramework/Classes/XCTestCase+AsynchronousTesting.m:236 /Users/iphonetest03/Desktop/shootr-ios/Tests/Performance。 m:42:错误:-[Performance testPerformanceExample]:失败:捕获“NSInternalInconsistencyException”,“API 违规 - 调用等待而没有设置任何期望。”

欢迎任何建议。谢谢。这是我的代码:

    @interface Performance : XCTestCase
       @property (nonatomic,strong)    XCTestExpectation *expectation;
       @property (nonatomic)           BOOL              serverResponse;
    @end

    @implementation Performance

       - (void)setUp {
          [super setUp];
          self.expectation = [self expectationWithDescription:@"Server response"];
       }

       - (void)tearDown {
          [super tearDown];
       }

       - (void)testPerformanceExample {
          [self measureBlock:^{
             [ShotQueueManager singleton].sendingrequestor = self;
             [[ShotQueueManager singleton] createShotQueueWithComment:@"iOS Shot creation performance test." andPhotoBinary:nil shotParent:nil userNameParent:nil andDelegate:self];
             [self waitForExpectationsWithTimeout:25.0 handler:^(NSError *error) {
                if (error) {
                   NSLog(@"Timeout Error: %@", error);
                }else{
                   XCTAssert(self.serverResponse);
                }
             }];
          }];
       }


       - (void)createShotResponseWithStatus:(BOOL)status andError:(NSError *)error {
          if (status && !error){
            self.serverResponse = YES;
            [self.expectation fulfill];
          }
       }
4

0 回答 0