1

I'm using MVVM with ReactiveCocoa, and OCMockito for testing. Suppose I have a ViewController A and ViewController B. A needs to perform a segue to B. I want to verify that when this happens, A passes the necessary data (the 'model') along to B via assignment first.

B looks like this:

@interface ViewControllerB : UITableViewController
@property(nonatomic, readonly) ViewModel *viewModel;
@end

Somewhere in view controller A, there is a statement:

 viewControllerB.viewModel.model = newModel;   // passes new data along for B to display

I want to verify that this assignment is happening, but viewModel property is readonly. The viewModel is initialised by the viewController's init method.

How could I mock out the viewModel here?

I could partial mock viewControllerB to return a mock viewModel, which then I verify on but https://github.com/jonreid/OCMockito/issues/38 says that partial mocks have since been removed. Why?!

fatuhoku
  • 4,815
  • 3
  • 30
  • 70

1 Answers1

0

I would modify init to accept 'ViewModel' and just assign it to readonly property. After this you could mock model and verify setter call.

I'm not big fan to modify API just to be able to test class but probably this change is natural for your design.

What I also notices - the double dots usage. This is quite obvious sign for me about necessary changes in API

Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
  • Yeah good point — I'm using storyboards at the minute, and so I let iOS handle my view controller instantiations. This is part of the reason why it's so painful: I can't define a separate `init` for which the data I wish to pass in is passed in. – fatuhoku Apr 01 '14 at 21:26