OCMock test if method does nothing but is called

86 Views Asked by At

Using OCMock, how do I test if a method does nothing?

- (void)myMethod:(BOOL)active
{
    if (active) {
        // Set property or do whatever
    }
    // Do nothing -- I need to test this scenario
}
1

There are 1 best solutions below

0
Erik Doernenburg On BEST ANSWER

You can create a partial mock to verify that the method is called. Then you have to devise a test that makes sure that the code inside the if statement isn't reached. How to do that depends entirely one what "// Set property or do whatever" does.

That said, if you have an if statement around the entire body of your method you might want to consider refactoring your code...