0

シミュレーターからの実行とコマンドラインからの実行で、GHUnit の結果に違いがあります。CLIでUIApplicationDelegateを使用するにはどうすればよいですか?

私のサンプルアプリでは、タグは stackoverflow-6479906です。Apple のOCUnitの例をGHUnitに転送したい。

予想:

「appDelegate」はどちらも nil ではありません。

現時点の:

シミュレーターからの実行は正常に機能します。ただし、cli から実行すると例外が発生します。https://gist.github.com/1046753

参照:アップルの単体テストの例

注: async NSURLConnection サンプルを読みましたが、解決策が見つからず、UIApplicationDelegate のケースで調整しました。

4

1 に答える 1

1

アプリデリゲートのテストケースを設計して、インスタンスをインスタンス化し、そこからメソッドを呼び出して出力をテストすることをお勧めします。

次のような構造を考えてみましょう。

@interface  FizzBuzzObjCStudyTest : GHTestCase {
   ObjCStudyAppDelegate *appDelegate;
}
@end

@implementation FizzBuzzObjCStudyTest
-(void)setUp
{
   appDelegate = [[ObjCStudyAppDelegate alloc] init];
}

-(void)tearDown
{
   [appDelegate release];
}

-(void) testAppDelegate
{
   GHAssertNotNil(appDelegate, @"Cannot find the application delegate", nil);

   // test other methods of ObjCStudyAppDelegate here, or make more test methods.
}
@end

GHUnitフレームワークは、CLIバージョンでUIApplicationDelegateを作成するUIフレームワークをバイパスします。実際、GUIバージョンのGHUnitは、GHUnitIPhoneAppDelegateと呼ばれる独自のUIApplicationDelegateを実際にインスタンス化しています。

GHUnitIOSMain.mから​​のスニペットは、GUIバージョン用に独自のアプリデリゲートを設定する方法を示しています。

// If GHUNIT_CLI is set we are using the command line interface and run the tests
// Otherwise load the GUI app
if (getenv("GHUNIT_CLI")) {
    retVal = [GHTestRunner run];
} else {
    retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIPhoneAppDelegate");
}
于 2011-07-17T10:26:53.333 に答える