0

3 つの非同期テストがあります。Xcode 内でテストするとすべて正常に動作しますが、テスト ケースを xcodebuild でビルドすることはできません。XCTestExpectation に関連する 11 のビルド エラーが発生します。

例:

error: unknown type name 'XCTestExpectation' @property XCTestExpectation *expectationNoImage;

最新のコマンド ライン ツール (Xcode 6.1.1) を使用しています。xcodebuild -version はそれを正しく述べています。

次のコマンドでビルドを実行しています

xcodebuild -project myprojasync.xcodeproj -scheme testScheme -configuration Debug -sdk iphonesimulator7.1 clean test | ocunit2junit

非同期テストとそれに対応するテストをコメントアウトすると、すべてが同じコマンドで完全に実行されます。

編集:これはテスト方法の1つです。

@property XCTestExpectation *expectationPass;

-(void)testTaskPass{

//Expectation
self.expectationPass = [self expectationWithDescription:@"Testing Async Works"];

[self.asyncTask getInfo]; //asynchronous call

[self waitForExpectationsWithTimeout:5.0 handler:nil];
}  

-(void)returnedFrom:(NSURL *)url with:(UIImage *)image{
    if([[url absoluteString] isEqualToString: @"http://correcturl.com"]){
    [self.expectationPass fulfill];
    }

}
4

2 に答える 2

1

あなたが期待をいつ満たすかは明らかではありません。あなたが持っていることがわかりました:

-(void)returnedFrom:(NSURL *)url with:(UIImage *)image;

そこにはフルフィルメントがありますが、あなたがそれを呼んだとき、私にははっきりしません。

これは私がそれを行う方法です:

@property XCTestExpectation *expectationPass;

-(void)testTaskPass{

   //Expectation
   self.expectationPass = [self expectationWithDescription:@"Testing Async Works"];

   //asynchronous call
   [self.asyncTask getInfo:^(){
       // some Assertions here...
       [self.expectationPass fulfill];
   }];

   [self waitForExpectationsWithTimeout:5.0 handler:^(NSError *error){
       XCTAssertNil(error, "Error");
   }];
}
于 2015-03-10T13:31:42.830 に答える