objective c - OSX application testing with OCMock -


i getting started osx tdd , ocmock, following http://pathfindersoftware.com/2009/01/testing-delegate-ocmock/.

right now, i'm @ phase application displays login upon startup , wish test user invalid/no credentials cannot login.

in detail, appdelegate set login view controller's delegate, attempt login (without setting credentials), delegate method didnotauthorizeuser called. i'm getting error in test. further details below.

object setup

  • appdelegate - real object, instantiates login vc , conforms protocol (somedelegateprotocol)
  • loginvc - mocked
  • application - mocked

test.m

id mocklvc = [ocmockobject mockforclass:[loginviewcontroller class]];  [appdelegate setloginviewcontroller:mocklvc];  id qtapp = [ocmockobject mockforclass:[nsapplication class]];  id logindelegate = [ocmockobject mockforprotocol:@protocol(somedelegate)];  [[mocklvc expect] setlogindelegate:logindelegate];  [[mocklvc expect] authenticatewithservice]; [[logindelegate expect] didnotauthorizeuser];   //this row returns nsinternalconsistencyexception //ocmockobject[loginviewcontroller] //unexpected method invoked setlogindelegate:<appdelegate> [appdelegate applicationdidfinishlaunching:qtapp];   [mocklvc verify]; 

appdelegate.m

- (void)applicationdidfinishlaunching:(nsnotification *)anotification {             [self.loginviewcontroller setlogindelegate:self]; } 

loginviewcontroller.h/.m

@property (weak) id < somedelegate > logindelegate;

error message

when calling application didfinishlaunchingwithoptions: following error in test,

nsinternalconsistencyexception ocmockobject[loginviewcontroller] unexpected method invoked setlogindelegate:<appdelegate>

do think setup in first place? ideas on how rewrite test or around error?

exchange logindelegate appdelegate resolves issue.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -