quattro_4 scribble

scribble 落書き (調べた事をただ落書きする)

NSScreencast Episode #82 TDD View Controllers with Specta and OCMock

TDD View Controllers with Specta and OCMock - NSScreencast

loginをmockしてテスト

  • Specta
  • Expecta
    • EXP_SHORTHAND - If not defined, expectations must be written with EXP_expect instead of expect
  • OCMock
  • [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
  • shared var
    • __block ViewController *_vc;
      • beforeEach(^{
  • expect(_vc)
    • .to
    • .toNot
      • .beNil()
      • .beInstanceOf([ViewController class]);
      • .equal(@"loginTapped:")
      • .beTruthy()
  • call viewDidLoad in test
    • UIView *view = _vc.view;
    • expect(view).toNot.beNil();
  • tap button
    • NSArray *actions = [button actionsForTarget:_vc forControlEvent:UIControlEventTouchUpInside];
    • expect(actions[0]).to.equal(@"loginTapped:");
  • mock
    • id mockLoginService = [OCMockObject mockForClass:[LoginService class]];
    • [[mockLoginService expect] verifyUsername:@"user1"
      • completion:[OCMArg any]
    • _vc.loginService = mockLoginService;
  • injection Constructor Injection vs. Setter Injection
    • Setter-Injection
    • Constructor-Injection

loginのmockあたり面倒くさそう