Monday, September 6, 2004

OCMock

OCMock is a new framework for testing Objective-C code using mock objects. Its trampoline-based interface is extremely simple:

Expectations
A trampoline records the message to expect, and the mock later checks to see whether your test code caused the same message to be sent to it. (It doesn’t seem to check the order or number of the messages, and unfortunately messages with non-object arguments don’t seem to be supported.)
Stubs
Using two trampolines, you can add a stub method to your mock object and set its return value.

From the user’s perspective, OCMock is not really any better than EasyMock (for Java), and it has considerably fewer features. However, it does fill a need in Objective-C, and it is a good example of what you can do in that language with relatively few lines of code.

See also: jMock (Java), pMock (Python).

Comments RSS · Twitter

Leave a Comment