Code: Learn about Unit Testing

Unit Testing

Unit testing is a procedure used to validate that individual units of source code are working properly. Rather than using humans to do this testing, we can draw on automated tools and frameworks to write code that tests our system and validates a set of assertions around state changes or interactions between components.

Simply put, automated unit tests are:

  • Structured
  • Self-documenting
  • Automatic and repeatable
  • Based on known data
  • Designed to test positive and negative actions
  • Ideal for testing implementation across different machines
  • Examples of configuration, implementation, and execution

Some of the key benefits of applying unit testing are:

  • It helps facilitate change through refactoring
  • Simplified integration by allowing a bottom up style of development
  • Tests become a documentation artifact helping to show valid assertions about system behavior

With BackgroundMotion we used unit tests to help assert our knowledge of the system we were building and also give us confidence that as we were evolving the system that those assertions held true. Rather than going through longer build and test cycles we were able to receive more immediate feedback about the state of the system as a whole.



Andrew describes the approach we took with Unit Testing on BackgroundMotion


Unit Testing with .NET

On BackgroundMotion we used a unit testing framework called NUnit.

"NUnit is a unit-testing framework for all .Net languages. Initially ported from JUnit, the current production release, version 2.4, is the fifth major release of this xUnit based unit testing tool for Microsoft .NET. It is written entirely in C# and has been completely redesigned to take advantage of many .NET language features, for example custom attributes and other reflection related capabilities. NUnit brings xUnit to all .NET languages."
http://www.nunit.org/

Alternative if you have Visual Studio 2005 Team Developer or Team Tester Editions you can use the integrated unit testing framework which is included with those editions.

Where can I find more information?