International Developer Logo Last Updated 24.07.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

In most conventional software projects, testing is usually scheduled as part of the final stage of development. While there is no substitute for thorough human testing of user pathways, this process can be very time consuming. It can also be very complicated, as finished applications usually differ significantly from the prototype outlined in the original specifications documents. Sometimes it's a result of a process that hasn't been fully thought through, and occasionally it's just the client's needs shifting midstream.

In any case, when a project veers course it usually leaves some debris behind. There might be unnecessary code fragments, quick-fixes to existing code as well as the inevitable change to embedded logic that results in unexpected behaviour. This scenario may sound familiar and, regrettably, there is no satisfactory solution. On the upside, though, it is possible to create an environment that makes tracing these side-effects much easier. Unless you've had your head buried in sand (or code) for the last few years, you will no doubt have heard of test-driven development (TDD). Because it requires testing code to be programmed before any application code is written, TDD reverses the conventional development process. While it slows progress at first, TDD saves time down the track by automatically locating problems when they occur. In this tutorial we look at how to use the NUnit framework to perform unit testing in .NET application. We also dig a little deeper than most unit testing tutorials, however, and demonstrate how mock objects can be used to ensure the integrity of unit tests by completely isolating the methods being tested. Note that although the sample code is written in C#, the methodology can be applied to all languages supported by the .NET framework.




   Previous Page  1 2 3 4 5 6 7 8 9 10 ... Next Page   

HAVE YOUR SAY
This article is rated  Rate this article