Successfully reported this slideshow.
Your SlideShare is downloading. ×

iOSアプリケーションの Unit Test

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 51 Ad

More Related Content

Slideshows for you (20)

Similar to iOSアプリケーションの Unit Test (20)

Advertisement

Recently uploaded (20)

iOSアプリケーションの Unit Test

  1. 1. iPhone  SDK  勉強会 iOSアプリケーションの Unit  Test
  2. 2. iPhone  SDK  勉強会 参考URL iOS  App  Development  Workflow  Guide http://developer.apple.com/library/ios/#documentation/Xcode/ Conceptual/ios_̲development_̲workflow/135-‐‑‒Unit_̲Testing_̲Applications/ unit_̲testing_̲applications.html
  3. 3. iPhone  SDK  勉強会 テストを習慣化するには
  4. 4. iPhone  SDK  勉強会 なぜテストを書かないか •めんどう •(UIなどと⽐比べて)  効果がわかりにくい •iPhoneアプリのテストってどう書いていいかわか らない etc.
  5. 5. iPhone  SDK  勉強会 ツール/フレームワークを使う •繰り返し実⾏行行するのが簡単 •⾃自動化できる •テスト結果として⾒見見えるようになる
  6. 6. iPhone  SDK  勉強会 無理理をしない •モデルのテストは書きやすいし、論論理理構造が変わ ることは少ないので、繰り返し実⾏行行するメリットが ⼤大きいのできちんと  (正常、異異常、例例外、境界値、 etc)  書いたほうがいい •いっぽう表⽰示については論論理理構造がひっくり返る ような変更更もよくあるし、そもそも何が正しいとい う状態を決定しにくいものなので、無理理に書こうと しない。
  7. 7. iPhone  SDK  勉強会 とはいえ、テストしやすい コードを書く努⼒力力はしよう •テストしやすいコードはほかから使いやすいコー ドなので、良良い設計につながる。 (カメラの画像を加⼯工するようなメソッドは、画像の 取得と加⼯工を分ける、 位置情報を使う場合はラッパーを1枚はさむと⾃自由 な値を返しやすくなる、など)
  8. 8. iPhone  SDK  勉強会 無理理をしない - (id)init { self = [super init]; if (self) { service = [[LDRService alloc] init]; service.delegate = self; } return self; [self  init]    nil   } 100%
  9. 9. iPhone  SDK  勉強会 ツール/フレームワークを使う •繰り返し実⾏行行するのが簡単 •⾃自動化できる •テスト結果として⾒見見えるようになる
  10. 10. iPhone  SDK  勉強会 単体テストをワークフローに 取り⼊入れる
  11. 11. iPhone  SDK  勉強会 OCUnit  (aka  SenTestingKit) GHUnit
  12. 12. iPhone  SDK  勉強会 OCUnit  (aka  SenTestingKit) GHUnit GHUnitがオススメ
  13. 13. iPhone  SDK  勉強会 OCUnit  と  GHUnit  の違い
  14. 14. iPhone  SDK  勉強会 OCUnit   GHUnit •Xcode標準 •Xcode⾮非標準 •XCodeと統合されたUI •テストランナーの独⾃自UI •Assertマクロが必要最⼩小 •Assertマクロが若若⼲干多い 限しかない •setUpClass  がある •⾮非同期のテストが(その •⾮非同期のテストが可能 ままでは)できない •OCUnitのテストケースも実 ⾏行行可能 •Viewの表⽰示テストができる
  15. 15. iPhone  SDK  勉強会 OCUnit   GHUnit •コマンドラインで実⾏行行 •コマンドラインで実⾏行行 •CIとの連携 •CIとの連携
  16. 16. iPhone  SDK  勉強会 環境設定  (OCUnit)
  17. 17. Xcode標準 iPhone  SDK  勉強会
  18. 18. iPhone  SDK  勉強会 環境設定  (GHUnit)
  19. 19. 導⼊入に⼿手順が必要 iPhone  SDK  勉強会
  20. 20. 導⼊入に⼿手順が必要 iPhone  SDK  勉強会
  21. 21. 導⼊入に⼿手順が必要 iPhone  SDK  勉強会
  22. 22. 導⼊入に⼿手順が必要 iPhone  SDK  勉強会
  23. 23. iPhone  SDK  勉強会 結果の表⽰示  (OCUnit)
  24. 24. テスト結果の表⽰示 iPhone  SDK  勉強会
  25. 25. iPhone  SDK  勉強会
  26. 26. iPhone  SDK  勉強会
  27. 27. iPhone  SDK  勉強会 結果の表⽰示  (GHUnit)
  28. 28. テスト結果の表⽰示 iPhone  SDK  勉強会
  29. 29. iPhone  SDK  勉強会 Assertの種類  (OCUnit)
  30. 30. iPhone  SDK  勉強会 STFail STAssertEqualObjects STAssertEquals STAssertEqualsWithAccuracy STAssertNil STAssertNotNil STAssertTrue STAssertFalse STAssertThrows STAssertThrowsSpecific STAssertThrowsSpecificNamed STAssertNoThrow STAssertNoThrowSpecific STAssertNoThrowSpecificNamed STAssertTrueNoThrow STAssertFalseNoThrow
  31. 31. iPhone  SDK  勉強会 Assertの種類  (GHUnit)
  32. 32. GHAssertNoErr(a1, description, ...) GHAssertErr(a1, a2, description, ...) iPhone  SDK  勉強会 GHAssertNotNULL(a1, description, ...) GHAssertNULL(a1, description, ...) GHAssertNotEquals(a1, a2, description, ...) GHAssertNotEqualObjects(a1, a2, desc, ...) GHAssertOperation(a1, a2, op, description, ...) GHAssertGreaterThan(a1, a2, description, ...) GHAssertGreaterThanOrEqual(a1, a2, description, ...) GHAssertLessThan(a1, a2, description, ...) GHAssertLessThanOrEqual(a1, a2, description, ...) GHAssertEqualStrings(a1, a2, description, ...) GHAssertNotEqualStrings(a1, a2, description, ...) GHAssertEqualCStrings(a1, a2, description, ...) GHAssertNotEqualCStrings(a1, a2, description, ...) GHAssertEqualObjects(a1, a2, description, ...) GHAssertEquals(a1, a2, description, ...) GHAbsoluteDifference(left,right) (MAX(left,right)-MIN(left,right)) GHAssertEqualsWithAccuracy(a1, a2, accuracy, description, ...) GHFail(description, ...) GHAssertNil(a1, description, ...) GHAssertNotNil(a1, description, ...) GHAssertTrue(expr, description, ...) GHAssertTrueNoThrow(expr, description, ...) GHAssertFalse(expr, description, ...) GHAssertFalseNoThrow(expr, description, ...) GHAssertThrows(expr, description, ...) GHAssertThrowsSpecific(expr, specificException, description, ...) GHAssertThrowsSpecificNamed(expr, specificException, aName, description, ...) GHAssertNoThrow(expr, description, ...) GHAssertNoThrowSpecific(expr, specificException, description, ...) GHAssertNoThrowSpecificNamed(expr, specificException, aName, description, ...)
  33. 33. iPhone  SDK  勉強会 SetupClass/tearDownClass   (GHUnit)
  34. 34. implementation MyTest // iPhone  SDK  勉強会 - (void)setUp { } // - (void)tearDown { } // - (void)setUpClass { } // - (void)tearDownClass { } // Tests are prefixed by 'test' and contain no arguments and no return value - (void)testA { } // Another test; Tests are run in lexical order - (void)testB { } // Override any exceptions; By default exceptions are raised, causing a test failure - (void)failWithException:(NSException *)exception { } @end
  35. 35. iPhone  SDK  勉強会 ⾮非同期のテスト  (GHUnit)
  36. 36. #import <GHUnitIOS/GHUnit.h> iPhone  SDK  勉強会 @interface LDRLoginTest : GHAsyncTestCase { SEL currentTest; } @end @implementation LDRLoginTest - (void)testLoginSucceeded { [self prepare]; currentTest = _cmd; LDRService *service = [LDRService service]; service.delegate = self; service.username = @"kishikawakatsumi"; service.password = @"password1234"; [service login]; [self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0]; }
  37. 37. - (void)serviceLoginSucceeded:(LDRService *)service { if (service.APIKey != nil) { iPhone  SDK  勉強会 [self notify:kGHUnitWaitStatusSuccess forSelector:@selector(testLoginSucceeded)]; } else { [self notify:kGHUnitWaitStatusFailure forSelector:@selector(testLoginSucceeded)]; } } - (void)service:(LDRService *)service loginFailedWithError:(NSError *)error { [self notify:kGHUnitWaitStatusFailure forSelector:@selector(testLoginSucceeded)]; } @end
  38. 38. iPhone  SDK  勉強会 OCUnitのテストケースを実⾏行行 (GHUnit)
  39. 39. OCUnitのテストケースを実⾏行行 iPhone  SDK  勉強会 OCUnit
  40. 40. iPhone  SDK  勉強会 Viewのテスト  (GHUnit)
  41. 41. #import <GHUnitIOS/GHUnit.h> iPhone  SDK  勉強会 @interface LoginViewTest : GHViewTestCase @end #import "LoginViewTest.h" #import "LoginViewController.h" @implementation LoginViewTest - (void)testLoginViewController { LoginViewController *viewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil]; GHVerifyView(viewController.view); } @end
  42. 42. iPhone  SDK  勉強会
  43. 43. iPhone  SDK  勉強会 まとめ •iOS  の  単体テストフレームワークはOCUnit  と   GHUnit •GHUnitがオススメ •実⾏行行環境は1度度作っておけば汎⽤用的に使えるの で覚えておいて損はない
  44. 44. iPhone  SDK  勉強会 おまけ GHUnit  のセットアップ
  45. 45. iPhone  SDK  勉強会
  46. 46. iPhone  SDK  勉強会
  47. 47. iPhone  SDK  勉強会
  48. 48. iPhone  SDK  勉強会
  49. 49. iPhone  SDK  勉強会
  50. 50. iPhone  SDK  勉強会
  51. 51. iPhone  SDK  勉強会 #import <UIKit/UIKit.h> #import "AppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, @"GHUnitIOSAppDelegate"); } }

×