Search code examples
.netvisual-studiounit-testingnunitbuild-automation

Automatic running of unit tests on build


I would love to know if there is a way I can get Visual Studio to run unit tests corresponding to a given assembly whenever I build it.

Given a solution containing projects structured like this:

Assembly1

Assembly1.Tests 

Assembly2 

Assembly2.Tests

Is there a way I can get the unit tests in Assembly2.Tests to run whenever Assembly2 is built?

That would be amazing.

I'm using Visual Studio 2008 Standard Edition.


Solution

  • You can use the nUnit console utility to run the tests as a post-build event for the individual project.

    You call the nunit-console.exe and supply your assembly containing your tests as an argument.

    "C:\Program Files\NUnit 2.5.7\bin\net-2.0\nunit-console.exe" "PathToTestAssembly.dll"

    or

    You can run the tests in the GUI:

    "C:\Program Files\NUnit 2.5.7\bin\net-2.0\nunit.exe" "PathToTestAssembly.dll" /run

    Edit:

    Removed the part about the post-build event for the test assembly project.