Sunday, September 04, 2005


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 -


Blogger Nicolas said...

That looks very interesting, indeed -- particularly because of the DSL..

I think it could be nice as a documentation tool (perhaps even by generating actual text automatically)

Also, it could be interesting to try with StepTalk/Smalltalk, I think with the cleaner syntax of Smalltalk it could be really nice..

9:33 AM

Blogger Stefan Kleine Stegemann said...

I find embedded DSLs to be a quite powerful approach that I try to use more and more where possible.

Generating documentation from a MockObject setup should be a relativly easy tasks but I'm unsure if the outcome is really valuable. At least it's just the code transformed to some other format without more information. Maybe it's nice for a summary.

MocKit in StepTalk is a great idea. I'm not very proficient in StepTalk but I like it's SmallTalk syntax. What I like about the idea is that if MocKit is interfaced with StepTalk, it would be possible to write small test scripts for an application.

12:19 AM

Anonymous Anonymous said...

The Death-Defying Audio Blog
A friend sent me a link to This Spartan Life , saying, "This new blog concept is kinda funny.
This is a terrific blog!

We have a autocad drafting services related site that you should see sometime to learn what's going on in the autocad drafting services world... look forward to your visit!

3:38 AM

Blogger Architectural Design said...

Hi, this is Jeff D Marsh with Yantram - cad design company, Construction Drawing Paper To CAD Conversion part of Yantram BPO Services Pvt. Ltd. We can serve your all kind of requirements likeElectrical Drawings, Plumbing Drawings, HVAC Drawings, Mechanical Engineering, Irrigation Drawings, Elevations Drawings, Foundation Drawings, Framing Drawings, Detail Sheet, Sections Sheet, Floor Plans, 3D Walkthroughs
To have better idea about the same just click on the link given hereby at
I like your work.

3:19 AM


Post a Comment

<< Home