Search The Blog
About this site

@RoyOsherove

Subscribe!

This site aims to connect all the dots of my online activities - from tools, books blogs and twitter accounts, to upcoming conferences, engagements and user group talks.

from 5whys.com
Twitter: @RoyOsherove
My Book: The Art of Unit Testing
Latest Posts
« Nice Handwriting fonts in Hebrew | Main | Write clearer more powerful tests with the unofficial NMock 2 Drop »
Saturday
Jun182005

Use Mock Logs instead of expectations when it makes sense

Len Holgate writes about a little known technique for using Mock Object testing which is very applicable in languages like C++ where Mock Object frameworks are hard to use and mocks are hard to create anyway.
 
Instead of doing "ExpectCall" and "Verify", use a simple logging technique in your mock object that captures all the events that happened to it. When the test finished, compare the actual log string to the expected log string.
If all is well they match and you know th interaction between your objects was OK.
 
I'd rather be using "Expect" but this is a great technique for when you don't want to muck around with writing mock code, but rather want to actually get somewhere in your production code fast.

PrintView Printer Friendly Version

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>