This article is written primarily to describe how unit testing relates to Object Oriented Programming and Test Driven Development (TTD) methodologies, with particular emphasis given on how to test using the NUnit (www.nunit.org) framework and Microsoft's .Net C# language.
I am by no means a guru at this subject, I am just writing down things I have learnt from reading books, newsgroups and talking to programmers, if you have any comments on how I can improve this article, or if I have made any errors, then I would love to hear back from you. You can email me at mark@markdawson.org, thanks in advance :-)
All examples are given in C# syntax, but most examples are easily translated into any other OOP language such as Java, C++ etc; so fans of Java and the like, please continue reading; it is the concepts behind the examples which are important, not the examples themselves. This document is also available in PDF.
The article is organised into the following sections:
Chapter 1 – A brief introduction into what is a unit test at a basic level.
Chapter 2 – Details the various stages in a project when you can write unit tests, and introduces the concepts of Test Driven Development (TDD).
Chapter 3 – Talks about why you might not want to use detailed unit testing in your project.
Chapter 4 – Discusses how unit testing relates to GUI code and the design patterns practises that should be followed.
Chapter 5 – An overview of some of the available Unit Testing Frameworks that are available to facilitate running unit tests.
Chapter 6 – An introduction to NUnit concepts, test attributes and the various NUnit applications.
Chapter 7 – Unit testing and databases.
Chapter 8 – Test coverage and quality.
Chapter 9 – Discusses the importance of catching issues early in the product lifecycle.
Chapter 10 – Outlines how to unit test methods not exposed on the public interface of an object.
Chapter 11 – Details how to debug your NUnit Tests through Visual Studio .Net 2003.
Chapter 12 – Example of how to run NUnit tests through the SharpDevelop IDE.
Chapter 13 – Conclusion.
Next Chapter: 1. Introduction to unit testing