Beginning to Mock with Rhino Mocks and MbUnit - Part 1
page 3 of 7
by Ben Hall
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 43676/ 56

Tool Support

There are a number of tools available to support mocking of objects and they are generally in one of two categories - static or dynamic. Static mock tools generate mock implementations as source code which is compiled with the test suite, while dynamic mock frameworks create the mock implementations at runtime.

Rhino Mocks is a dynamic mock object framework for the .NET platform which allows developers to create mock objects and verify the interactions while unit testing. Rhino Mocks is a very powerful framework, in this part I will only discuss how to get started.

Rhino mocks is an open source framework created by Ayende Rahien and is available to download from the official web site. There are alternative frameworks available such as EasyMock.Net and NMock.

Rhino mocks works with all the .NET unit testing frameworks currently available. For this series I will be using MbUnit, which can be downloaded from, as it has some excellent features that improve the unit tests.

View Entire Article

User Comments

Title: "Program against interfaces"   
Name: Rogério Liesenfeld
Date: 2009-10-06 5:01:32 PM
What exactly is meant here by "program against interfaces, one of the core OO design rules"?

Creating an IDateTime interface with a single DateTimeController implementation class is absolutely NOT what was intended by the GoF book (Design Patterns) when they said "program to interface, not an implementation".

That "core OO design rule" is about something else: polymorphism; and it's really only applicable in the context of reusable OO software, specifically for dependencies between subsystems. Not at all the case for the example in this article.
Title: Question   
Name: bangi
Date: 2009-05-06 9:37:40 AM
Is it possible to mock an object to is called by the method that I am calling. Eg. 1SomeInterface has a method called GetUsers. GetUsers calls a method called findusers which belongs to a Interface IDataAccess. Is it correct to make a mock object for IDataAccess in my Test class hoping that when I call ISomeInterface when ISomeInterface gets to the IDataAccess.findusers() the mock version will be user instead of the real method.
Title: Thanks   
Name: dotnetguts
Date: 2008-10-27 2:23:56 PM
Thanks, Good Information.

Title: Excellent   
Name: Iran
Date: 2008-09-13 7:17:49 AM
Thanks a lot Ben for providing a simple start up guide for Rhino mocks
Title: Stubs v Mocks   
Name: Ben Hall
Date: 2008-05-27 6:49:28 AM
Title: I recomended this book   
Name: Carlos
Date: 2008-05-27 6:04:34 AM
This post is very well, but are confused concepts(STUBS-MOCKS)
I recommend reading this book is really good.
Title: Diference Stubs and Mocks   
Name: Carlos
Date: 2008-05-27 4:28:18 AM
I think these confusing terms between STUBS and MOCKS.
You've created a mock, for help to test the class, this is a stub not a mock. I recommend you read this article.
Title: Great Tutorial   
Name: Steve Smith
Date: 2008-03-22 12:55:29 PM
It didn't click for me until I read this - been trying to learn Rhino Mocks off and on for the last week. Nice job!
Title: Thanks for sharing   
Name: Jeena
Date: 2008-01-25 9:32:33 AM
Very good article. Thanks a lot
Title: Good introduction to Rhino Mocks   
Name: Tod Birdsall
Date: 2007-12-27 5:55:43 PM
Thanks for the nice introduction. It was very clear and easy to follow.
Title: .   
Name: Pawel Tarnik
Date: 2007-10-10 8:39:38 AM
Nice article, I look forward to reading the next part.
Title: Beginning to Mock with Rhino Mocks and MbUnit - Part 1   
Name: Lee
Date: 2007-10-09 7:46:47 PM
Thanks for the article - it's clear and easy to follow.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-04-15 6:11:39 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search