I recently started development of a small
MockObjects Cocoa/GNUstep framework called "MocKit". MockObjects is a technique to test for interactions of objects instead of state. MocKit is inspired by the
jMock framework that is written in Java. The interesting thing about jMock is that it provides a small embedded domain specific language for defining expectations about object interactions. With expectations, you basically say what messages you expect to be send to an object during a test scenario. The document
"Mock Roles, not Objects" describes this approach in more detail. MocKit follows the ideas of jMock although it's not an exact reimplementation.
Here is a little example.
id mock=[MockObject mockForClass: [MyClass class]];
[[[[mock expect: @selector(someMethodWithArg:)]
times: 2]
with: ArgEquals([NSNumber numberWithInt: 42])]
willAlwaysReturn: @"this is the answer"];
// run test scenario
[mock verify];
The approach of providing an embedded domain specific language for MockObjects is what makes MocKit different from
OCUnit. OCUnit uses a recorder based approach. You first "record" the messages that are expected to be send to an object and run your test scenario. The messages send to the object during the test must match the previously recorded messages. The main advantage of MocKit is that it provides a more flexible approach. If focuses on expressing rules for object interactions. The resulting code (see example above) does not only test but also documents a system. By looking at the test code, one can easily see how objects in a system behave.
MocKit is currently in a usable state although it needs some polishing before I will release an official version. If you are interested, you can browse
the darcs repository online. If you want to try MocKit, download
the repository archive. It contains a makefile for the GNUstep environment as well as an XCode project (XCode 2 is required). For an introduction read
MocKit/Documentation/MocKit.text. If you have questions or problems you can send me a mail (stefankst - at - gmail.com).