Home > Mocks, XP > SimpleMock

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:

  1. Reports failure when no expectations are set
  2. Reports failure when expectations are not met
  3. Reports failure when unexpected calls are found
  4. Succeeds when all expectations are met
  5. Allows you specify if expectations are positionally sensitive or not

SimpleMock will not do the following:

  1. Set return values for functions
  2. Mock parameters
  3. 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.

Mocks, XP

  1. April 27th, 2007 at 04:45 | #1

    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?

  2. jdawkins
    April 30th, 2007 at 10:08 | #2

    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.

  3. March 26th, 2010 at 02:07 | #3

    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!

  4. May 27th, 2010 at 04:37 | #4

    I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading.

  5. Roger
    June 23rd, 2010 at 04:39 | #5

    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.

  6. Roger
    June 27th, 2010 at 21:22 | #6

    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

  7. August 3rd, 2010 at 17:58 | #7

    An amazing machine, you deserve to 1. These fantastic shoes can be a brilliant and attractive. Enjoy and of itself.

  8. August 6th, 2010 at 03:44 | #8

    I really liked your article. Keep up the good work.

  9. August 6th, 2010 at 21:08 | #9

    Japan Flowers
    Really like this website, this really helps and very useful.

  10. August 18th, 2010 at 01:58 | #10

    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.

  11. August 21st, 2010 at 05:21 | #11

    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.

  12. August 23rd, 2010 at 05:49 | #12

    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

  13. August 30th, 2010 at 23:22 | #13

    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.

  14. September 1st, 2010 at 19:56 | #14

    Best canon Coffee Mugs! Funny, Cute, & Humorous Unique designs. Also find Travel Mugs, Coffee Cups also, or Create Photo Personalized Mugs & Drinkware

  1. August 19th, 2009 at 00:34 | #1
  2. March 17th, 2010 at 11:54 | #2

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word