+N Consulting, Inc.

Websites | Databases | Consulting | Training

Unit Testing as part of the build process in VS2005

We had a practice which included unit testing for a while now, but it entailed Nunit and MBunit with various build frameworks such as CruiseControl and VisualBuilder.

We are running VS2005, and wanted to include running the tests on developer boxes as part of a build, so that failed tests will flunk the build.

Using a post build event, this is easily done. In the Post Build Events, enter:

CD $(TargetDir)
"$(DevEnvDir)MSTEST.exe" /testcontainer:$(TargetFileName)

The quotes around the MSTEST full path ensure that the space in the name “Program Files” is resolved correctly.

Changing directory to the target directory is easier than setting all explicit paths etc.

This could have been achieved by running a continuous integration server on each machine, but raises the setup complexity.

If MSTEST returns a less than success code, the build will fail.

If you further want to speed development compile/run cycle, you can create a new configuration:

Configuration Manager -> Active Solution Configuration (drop down) -> “New” -> name a new debug configuration “Debug No Test”

In the new configuration, check each project in the solution except the test project.


We use cookies to personalise content, to allow you to contact us, to provide social media features and to analyse our site usage. Information about your use of our site may be combined by our analytics partners with other information that you’ve provided to them or that they’ve collected from your use of their services. You consent to our cookies if you continue to use our website.