SimpleMock
March 22nd, 2007
I recently had occasion to demonstrate how to write a very lightweight mocking framework. The result was SimpleMock. SimpleMock does four things:
- Reports failure when no expectations are set
- Reports failure when expectations are not met
- Reports failure when unexpected calls are found
- Succeeds when all expectations are met
- Allows you specify if expectations are positionally sensitive or not
SimpleMock will not do the following:
- Set return values for functions
- Mock parameters
- Or any of the other really cool things that PascalMock1.1 will do
Tests are included in the archive. These will show you how to use it.
Download the code here: SimpleMock.zip
Updated to added behavior #5 above. I recently had a reason to not care in what order method expectations are called.
Hi, I am the PascalMock author.
I would like to say i like your web site and the idea behind very much.
It’s good to see more mocks in Delphi!
Some things I like about SimpleMock:
- it’s simple
- it use interfaces (more than PascalMock 1.1)
- expectations can be positionally sensitive, which can be usefull
I am wondering, have you tried PascalMock and imagine things in a different way?
Thanks Harghh!
I have used PascalMock and I think it is very good.
SimpleMock evolved as an excerise to show how mocks and mock frameworks were not difficult or “works of magic” =P . Many engineers don’t understand mocks and as such they shy away from them. I wanted to show my co-workers how easy it is to use mocks and that they could even write a mock framework with very little code.
It’s a great post Man, you really are a good writer! I’m so glad someone like you have the time, efforts and dedication writing, for this kind of article… Helpful, Useful, and Charitable.. Very nice post!
I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading.
Is there any tutorials on SimpleMock. I’ve looked at it and would like to try it out on some of our legacy code in Delphi 5.
Also, how would I use SimpleMock if I wanted to set an expection on a function return? I need to set the internal state of a class