Sunday, 3 May 2009

Setup xUnit.net for unit testing in ASP.NET MVC RTM

Environment:

  • Visual Studio 2008 Pro
  • xUnit.net v1.5 (build 1.5.0.1479)

If you are using a zip file downloaded from the Source Code section of their site, extract it on a temp folder and move the binaries from the Samplesxunit folder to your destination of choice. If you are using the zipped binaries from their downloads page, simply extract them to your desired location.

The next step is running xunit.installer.exe and enabling support for ASP.NET MVC. The result should look like this:

xunit_installer_success.png

If the installer throws an exception like this one:

xunit_installer_error.png

then you should create manually the folder specified in the error message (usually the Test folders).

As a result, xUnit.net will appear as an option for unit testing during creation of a new ASP.NET MVC application:

xunit_vs_new_project.png

In order to run the tests, I defined an external command (which works when the project containing the tests is selected in Solution Explorer):

xunit_vs_run.png

For more details about xUnit.net usage, please read An Introduction to xUnit.net for ASP.NET MVC Developers from Stephen Walther’s blog, and also check the documentation from the xUnit.net CodePlex site