Beginning to Mock with Rhino Mocks and MbUnit - Part 2
page 1 of 5
Published: 15 Oct 2007
Abstract
This is the second in a series of articles covering the Rhino Mocks mock object framework for the .NET Framework. In this part, the author examines when mock objects might be useful and explains how to implement the common uses of mock objects in your unit tests.
by Ben Hall
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 36495/ 49

Introduction

This is the second in a series of articles covering the Rhino Mocks mock object framework for the .NET Framework. The aim of this series is to provide you with an understanding of how mock objects are used, how they can improve the quality of your unit tests and how mock objects can make the difficult to test sections of your application simpler to test.  

In this second part, I cover when mock objects might be useful and explain how to implement the common uses of mock objects in your unit tests. I discuss how to mock your data layer, which involves accessing both a database and a web service, when testing your business layer and how to actually implement the data layer keeping it both flexible and mockable.

If you do not have experience with mock frameworks and have not read the first part, then I recommend you read that first before coming back to this article.


View Entire Article

User Comments

Title: saf   
Name: saf
Date: 2012-12-06 12:46:37 AM
Comment:
saf
Title: SE   
Name: Rakib
Date: 2010-05-12 6:29:21 AM
Comment:
Its a very good article
Title: CannotConnectToDatabaseException   
Name: Ben Hall
Date: 2008-04-03 10:12:17 AM
Comment:
CannotConnectToDatabaseException is a custom exception I created in my production code (what is being tested) because I couldn't create a SqlException to raise from that side :)
Title: Listing 5: Expect.Call GetAllBooks but call GetBooksWithPriceBelow   
Name: Bert Vanpeteghem
Date: 2008-01-15 5:13:50 AM
Comment:
A question on Listing 5:
In the record-section: there is Expect.Call(mockDataAccess.GetAllBooks())...
And in the playback-section:
bookService.GetBooksWithPriceBelow(10);

Shouldn't the call to GetBooksWithPriceBelow also be in the record?
Title: S/W Engineer   
Name: Bill Campbell
Date: 2007-10-15 12:52:47 PM
Comment:
Here's a link to the first one:

http://aspalliance.com/1400_beginning_to_mock_with_rhino_mocks_and_mbunit__part_1
Title: Beginning to Mock Part 2 Needs a Part 1 Link   
Name: Roger Jennings
Date: 2007-10-15 11:01:12 AM
Comment:
There's no obvious link to Part 1 in the introduction, which recommends it for readers unfamiliar with mock frameworks.

--rj

Product Spotlight
Product Spotlight 





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


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 3:43:49 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search