Use Mock Logs instead of expectations when it makes sense

By Roy Osherove In Agile Related, Testing Guidelines

Markdown version

Historical article · Originally published June 18, 2005; technical details may be outdated.

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.

More in Agile Related

All posts in Agile Related