■ダウンロード
■導入
ターゲットの追加
- Project navigatorでProjectを選択し、Add Targetを選択
- Window Based ApplicationでProduct NameをTestsとして適当にターゲットを追加
frameworkの追加
Project navigator > Projectを選択 > Target > Testsを選択 > Build Phases > Link Binary With Libraries
ダウンロードしてできたframeworkを追加する。
Info.plist
Test/Supporting Files/Test-Info.plistを選択してMain nib file base nameの属性を削除する。
ファイルの削除
Test配下の以下のファイルを削除する。
- TestAppDelegate.h
- TestAppDelegate.m
- MainWindow.xib
- Supporting Files以外のディレクトリ
リンク
Project navigator > Projectを選択 > Target > Testsを選択 > Build Setting > Other Linker Flag
以下の記述を加えてください。
- -ObjC
- -all_load
Test/main.m
以下の部分を
int retVal = UIApplicationMain(argc, argv, nil, nil);
以下のように変更する。
int retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIOSAppDelegate");
■テストケース
Test配下にテストを配置する。但し、ターゲットはTestsにしてファイルを新しく追加する。
Test/MyTest.m
#import <GHUnitIOS/GHUnit.h> @interface MyTest : GHTestCase { } @end @implementation MyTest - (void)testStrings { NSString *string1 = @"a string"; GHTestLog(@"I can log to the GHUnit test console: %@", string1); // Assert string1 is not NULL, with no custom error description GHAssertNotNULL(string1, nil); // Assert equal objects, add custom error description NSString *string2 = @"a string"; GHAssertEqualObjects(string1, string2, @"A custom error message. string1 should be equal to: %@.", string2); GHAssertEquals(1, 1, @"test"); } // わざとエラーを出してみる - (void)testNums { GHAssertEquals(1, 2, @"test"); } @end