Why Kiwi for iOS testing

I just decided on Kiwi for a project rather than OCMock + OCUnit. These are Kiwi’s selling points for me:

  1. Stubbing class methods is simpler. With OCMock, I needed to create a special class (one per project) to do method swizzling. No such problem with Kiwi – just [MyClass stub:@selector(doFoo) andReturn:myBar];
  2. Mock failures with Kiwi show up on the line that failed in Xcode (they showed up in strange places with OCMock).
  3. Kiwi’s test failures produce descriptive, unambiguous error messages (as opposed to the not-so-helpful messages from OCMock & OCUnit).
  4. Syntax. should, equal, stub, mock, and other readable methods (rather than STAssertEqualObjects and other not-so-easy-to-read macros & methods). Check out the Expectations page and the Mocks and Stubs page to decide for yourself.
  5. No need to [mock verify], which is required with OCMock.

Go ahead and give Kiwi a try. I think you’ll like it.

Further reading

Test Driving iOS Development with Kiwi by Daniel Steinberg is an excellent book on the topic.

Getting Started with Kiwi 2.0 will walk you through the setup process.

Or you can read the official documentation.