Any developer can give you a number of reasons why Unit Testing is important – however few actually do it and even if they do code coverage isn’tgreat. My knowledge of Unit Testing focuses on 3 areas:

  • Compile Tests (MSBuild, dotnet build)
  • Core Functionality Tests (NUnit, XUnit)
  • Front End Tests (Selenium, SoapUI)

Compile Tests may seem like an obvious step, but a remarkable number of people will commit a solution without checking if it builds. Post-build events or continuous integration can easily check whether or not your solution will compile, if it can run without encountering errors. I am a firm practitioner in the belief that the first step of any build test, should be “Does it actually build”.

Core Functionality Tests are what most will consider when writing Unit Tests, NUnit and XUnit are great ways to test core pieces of  functionality, making use of mock frameworks (Moq, Rhino) to test the core functionality of your code without any impact to any data sources you have. I aim to have my projects include unit testing to be run via build script or build server to ensure quality.

The front end is an often forgotten and untested area, but tools are available to test your API and your web interface. Tools such as Selenium can be programmed from within you unit tests to run against a running site and assert actions. SoapUI can fire formatted requests at multiple types of online APIs to ensure that any changes you’ve made to your service are unaffected.