Search code examples
objective-cocmockito

How to stub a method that returns void


I hope my question is not too basic, as I am new to both obj-c and OCMockito!

I have a void method that I want to stub, so that it does not perform its actions when running a test.

My Method:

-(void)myVoidMethod { .. }

I would like to stub it in a way similar to this:

[given([mockDataManager saveChangesToCoreData])];

However if I dont specify a "willReturn" statement I get the following error: "Argument type 'void' is incomplete"

How can I achieve this in OCMockito?


Solution

  • After getting more details from comments I decide to write the answer here.

    IMO partial stubbing (spies) are bad practise. I used it two times in really big legacy project and I would like to change that to something cleaner at some point.

    The same opinion is shared between other people. As quick solution you could follow advice from here - subclass and override the method.