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
An amazing machine, you deserve to 1. These fantastic shoes can be a brilliant and attractive. Enjoy and of itself.
I really liked your article. Keep up the good work.
Japan Flowers
Really like this website, this really helps and very useful.
We sincerely got a kick out of your post. It appears like you have really put a good amount of effort into your post and this world need a lot more of these on the net these days. I don’t have much to say in retort, I only wanted to comment to reply well done.
I found your website perfect for my needs. It contains wonderful and helpful posts. I have read most of them and got a lot from them.
Thanks for the live-tweeting of the hearings! I appreciated being able to keep up with the hearings, and your context.
Nice article Tx man
I found your website perfect for my needs. It contains wonderful and helpful posts. I have read most of them and got a lot from them.
Best canon Coffee Mugs! Funny, Cute, & Humorous Unique designs. Also find Travel Mugs, Coffee Cups also, or Create Photo Personalized Mugs & Drinkware