---
title: "I changed my mind - Mock objects are wrong for database unit testing"
url: "https://osherove.com/blog/2004/12/10/i-changed-my-mind-mock-objects-are-wrong-for-database-unit-t.md"
canonical: "https://osherove.com/blog/2004/12/10/i-changed-my-mind-mock-objects-are-wrong-for-database-unit-t.html"
published: "2004-12-10T01:04:00"
updated: "2004-12-10T01:04:00"
tags: ["Agile Related"]
author: "Roy Osherove"
description: "More than a year ago I wrote about the problems in database testing. I also stated that I feel it's totally wrong to run your unit tests against a live test database, but instead you should be using mock objects to save…"
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/"
---

# I changed my mind - Mock objects are wrong for database unit testing

By Roy Osherove December 10, 2004 In [Agile Related](https://osherove.com/blog/category/agile-related)

**Historical article** · Originally published December 10, 2004; technical details may be outdated.

More than a year ago I wrote about the problems in database testing. I also [stated](http://weblogs.asp.net/rosherove/archive/2003/09/30/29734.aspx) that I feel it's totally wrong to run your unit tests against a live test database, but instead you should be using mock objects to save you from all the trouble.

Boy have things changed since then. I take back what I said. For a long time now I've been doing DB testing without mock objects, because I believe that's currently the best way to make sure you test data access logic **and** integration with the database procedures and views.

There are now several easy to implement solutions to the "how-the-hell-do-I-roll-back-the-changes-i've-made-to-the-db" problem(see [this article](http://weblogs.asp.net/rosherove/archive/2004/07/20/187863.aspx), [mbUnit](http://mbunit.tigris.org/) , [xtUnit](http://weblogs.asp.net/rosherove/archive/2004/10/05/238201.aspx) and [this one about extending the new Nunit](http://weblogs.asp.net/rosherove/archive/2004/12/05/275164.aspx) as well for several options for doing the same thing).

With those - there's no reason for you not to do it.

Funny how things change overtime. Like any other thing, but usually more, software development is one of those things that looking back 6 months from now I'll **always** say to myself "Gosh! if I knew then what I now!"..

## Lessons on this topic

- [TDD Q & A](https://courses.osherove.com/courses/tdd-in-net-in-hebrew/tdd-q-and-a/) · TDD in .NET in Hebrew

## More in Agile Related

[All posts in Agile Related](https://osherove.com/blog/category/agile-related)

- Jan 1, 2005

    ### [The case for staged delivery and Agile methodologies](https://osherove.com/blog/2005/1/1/the-case-for-staged-delivery-and-agile-methodologies.html)

- Dec 29, 2004

    ### [Comparing C++ unit testing frameworks](https://osherove.com/blog/2004/12/29/comparing-c-unit-testing-frameworks.html)

- Dec 7, 2004

    ### [MSF is a fraud? A response](https://osherove.com/blog/2004/12/7/msf-is-a-fraud-a-response.html)

- Dec 7, 2004

    ### [Mockpp - Mock Objects for C++](https://osherove.com/blog/2004/12/7/mockpp-mock-objects-for-c.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/
