---
title: "Write clearer more powerful tests with the unofficial NMock 2 Drop"
url: "https://osherove.com/blog/2005/6/17/write-clearer-more-powerful-tests-with-the-unofficial-nmock.md"
canonical: "https://osherove.com/blog/2005/6/17/write-clearer-more-powerful-tests-with-the-unofficial-nmock.html"
published: "2005-06-17T22:18:00"
updated: "2005-06-17T22:18:00"
tags: ["Agile Related"]
author: "Roy Osherove"
description: "[If you know what a Mock Object and NMock is - feel free to skip the following paragraph] NMock is a .NET library (framework actually) to help write unit tests for objects that have to interact with other objects (Like…"
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/"
---

# Write clearer more powerful tests with the unofficial NMock 2 Drop

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

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

_\[If you know what a Mock Object and NMock is - feel free to skip the following paragraph\]_

NMock is a .NET library (framework actually) to help write unit tests for objects that have to interact with other objects (Like Class "MailSender" interacts with class "MailServer", for example). It allows you to "mimic" one or more objects during the test so that you could check various things that would be hard to check under normal circumstances (For example - instead of checking that an actual mail message was sent ton an exchange server, you would just check that a correct call with correct parameter values was executed against the server class. You do this by "mimicking" the server class and replacing it with your own - using this NMock library).

In short, the library allows you to create what is known as a "Mock Object". If you want to get deep into what this really means, read Fowler's opinion on this. Here's a shorter, more technical concise idea (exec summary type).

Anyway,

Looks like there's a new NMock in town (though it's still in "source" mode and not yet official).

It's the NMock you wanted but your daddy didn't let you. And It's called NMock2.

Looks like [Vaderpi has tried it out and loved it](http://vaderpi.scottandlaurie.com/blog/?p=185).

What does it "Do"? well, it does some stuff the [NMock](http://www.nmock.org/) you know and love today can't.

- Finally able to verify that Events have occurred on the class under test (Much like [my feeble attempt here](https://weblogs.asp.net/rosherove/archive/2005/06/13/EventsVerifier.aspx))
- Has an all new way of syntax - much more like it's original padre - the [JMock](http://www.jmock.org/) framework from Java. Here's a small example:
    - **Expect****.Once.On(joker).Method("Respond").With(Is.EqualTo("Who's there?"));**

        **.Once.On(joker).Method("Respond").With(Is.EqualTo("Who's there?"));**
    - **Expect****.AtLeastOnce.On(joker).Method("Ha");**

        **.AtLeastOnce.On(joker).Method("Ha");**
- Still cannot Mock actual classes (which is when you bring in heavy duty stuff like [TypeMock.net](http://www.typemock.com/))

- Lots more I still haven't checked out.

So, if you're into "real" testing where you need Mock Objects, this should be worth checking out. How? There are two ways:

**The Loooong Way**

1. Read the full instructions [here](http://www.nmock.org/source.html)
2. Get some sort of [CVS manager](http://www.tortoisecvs.org/) (Like Sourcesafe - only very much not!)
3. Use it to get the latest version from the site
4. Build the things
5. Use it

**The Short Way**

1. I already did that so you don't have to. Download the unofficial drop here: [http://files.osherove.com/NMock2\_Drop.zip](http://files.osherove.com/NMock2_Drop.zip).
2. It includes source and binaries.

[Be sure to read the License!](http://www.nmock.org/license.html)

A great way to see how you should use it (including call syntax) is to **read it's acceptance and unit tests**. They're right there along with the code so they make for perfect API documentation for the uninitiated. Just another great example of unit tests doubling as documentation (though I agree that that's not **all** the documentation a project should have).

Have fun!

(link found via [TestDriven.com](http://www.testdriven.com/modules/news/index.php?storytopic=12))

## More in Agile Related

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

- 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 18, 2005

    ### [Use Mock Logs instead of expectations when it makes sense](https://osherove.com/blog/2005/6/18/use-mock-logs-instead-of-expectations-when-it-makes-sense.html)

- Jun 16, 2005

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

- Jun 16, 2005

    ### [Mock Objects vs. "Inherit & Override"](https://osherove.com/blog/2005/6/16/mock-objects-vs-quotinherit-amp-overridequot.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/
