views:

128

answers:

1

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 amaaaaaaaaaazing.

I'm using Visual Studio 2008 Standard Edition.

Thanks

David

+3  A: 

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.

fletcher
I won't be able to try this just yet, but if you're right it's a rare case of something really useful being easy to set up. I'll hit you back in a bit...
David
Sorry, does your caveat (about where to put the post-build event) apply to both of your alternatives, or only the latter?
David
Only the latter, as the $(TargetPath) variable refers to the outputted assembly for that project. So, if you used the latter postbuild event in the build for the main assembly (that which is under test) it wouldn't work in nunit.
fletcher
Oh, I understand. Thanks for the clarification.
David
This is one of the most useful things I've learnt on SO. Thanks again.
David