0

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
}
h.and.h
  • 690
  • 1
  • 8
  • 26

1 Answers1

1

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...

Erik Doernenburg
  • 2,933
  • 18
  • 21