---
title: "Use Mock Logs instead of expectations when it makes sense"
url: "https://osherove.com/blog/2005/6/18/use-mock-logs-instead-of-expectations-when-it-makes-sense.md"
canonical: "https://osherove.com/blog/2005/6/18/use-mock-logs-instead-of-expectations-when-it-makes-sense.html"
published: "2005-06-18T12:49:00"
updated: "2005-06-18T12:49:00"
tags: ["Agile Related", "Testing Guidelines"]
author: "Roy Osherove"
description: "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…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Use Mock Logs instead of expectations when it makes sense

By Roy Osherove June 18, 2005 In [Agile Related](https://osherove.com/blog/category/agile-related), [Testing Guidelines](https://osherove.com/blog/category/testing-guidelines)

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

[Len Holgate](http://www.lenholgate.com/) 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](http://www.lenholgate.com/archives/000421.html) 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](https://osherove.com/blog/category/agile-related)

- Jun 26, 2005

    ### [\[Tool\] Convert NUnit tests to Team System Tests](https://osherove.com/blog/2005/6/26/tool-convert-nunit-tests-to-team-system-tests.html)

- Jun 20, 2005

    ### [June at Agile Israel: Implementing change in an organization + A Bug's Life](https://osherove.com/blog/2005/6/20/june-at-agile-israel-implementing-change-in-an-organization.html)

- Jun 17, 2005

    ### [Write clearer more powerful tests with the unofficial NMock 2 Drop](https://osherove.com/blog/2005/6/17/write-clearer-more-powerful-tests-with-the-unofficial-nmock.html)

- Jun 16, 2005

    ### [A good tester](https://osherove.com/blog/2005/6/16/a-good-tester.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
