News


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.

posted @ Tuesday, October 23, 2007 8:15 AM |

Comments

Gravatar # re: Unit Testing as part of the build process in VS2005
Posted by Chris Eargle on 10/23/2007 10:30 AM
Why not set up a standalone continuous integration server? That way you can have it handle deployment and generate coverage/fxcop reports as well.
Gravatar # re: Unit Testing as part of the build process in VS2005
Posted by nuri on 10/23/2007 7:50 PM
A continuous integration server is in place on a dedicated build server.
In addition to that we wanted developers to be in the habit of writing code that is tested from the get go.
Before code is checked into the source control, each *compilation* of the solution include unit tests invocation.
Our server is set to build + test etc on check-in event so only code that the developer felt is stable enough is built there and "released" to the rest of the dev team and the stakeholders.
Until that point, the developer has the tests running and solutions can have a "pre debug" smoke test.

Gravatar # re: Unit Testing as part of the build process in VS2005
Posted by Chris Eargle on 10/24/2007 3:11 AM
It is nice to have your tests run at compile time, but this would never work in my environment. The tests take too long to run, so we solved it through process instead. We're using the TDD plugin for VS, so developers can run individual tests while coding, then run a full test before checking in.

Out of curiosity, are you checking test coverage? We're using NCover and NCoverExplorer for that.
Gravatar # re: Unit Testing as part of the build process in VS2005
Posted by nuri on 8/27/2008 8:59 AM
I got asked recently regarding this post:

"Although I have 2 test failing for that test project. Please help me out even if my test fails the build shouldnot fail.."

To be clear, the whole point of integrating the post build event and running unit tests is that your build DOES fail if unit tests fail. This way, the red-fix-green cycle can happen and you don't let cod that doesn't pass unit tests succeed a build.

If one wants to do a different approach, one would probably create another build target (eg: DebugNoTests) that is the same but doesn't build the test project. If you are using unit testing, I'd reccomend just to run them and resolve all failure before you use the software though.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: