International Developer Logo Last Updated 27.08.08 at 11.48
On Sale
This months front cover, click to see the table of contents.
Subscribe
 
TUTORIALS

Using Mock Objects in Test Driven .NET Development


Neil Kidd   01.11.05

Here a mock transaction is used to enclose three expected delete commands executed from stored procedures. As the test shares the connection object via the SetUp routine, there is no need to call the transaction object's Verify method. Instead, this is automatically called from the connection object's Verify method in the fixture's TearDown method.


Mock on
Test driven development has been around for a few years now and, while unit testing frameworks such as NUnit are increasingly popular, the use of mock objects still seems to largely be considered an esoteric art. While the learning curve is sharpened by the lack of good documentation for the existing .NET mock object frameworks, perseverance is usually well rewarded. For example, there is little worse than wasting time debugging failed unit tests only to find the problem lies with an external dependency that is causing your otherwise perfect class to misbehave!


Sample code on the CD
NMockExample.zip
DotNetMockExample.zip

Online Resources
http://www.nunit.org
http://www.nmock.org/
http://sourceforge.net/projects/dotnetmock/
easymocknet

CD Files
NUnit 2.2.0

NMock

DotNetMock 0.76

EasyMockNet 1.1

TestRunner for VS.NET ::




   Previous Page  ... 11 12 Next Page   

HAVE YOUR SAY
This article is rated  Rate this article