Use Visual Studio's Post-Build Events to Automate Unit Testing Running
Whether you're into test driven development (TDD) or test after development (TAD), or you're into having your code get br0xored by not testing (doh!)... unit testing is all over the development world. You're a silly-goose if you haven't heard about it. In any case, using Visual Studio's post-build event process is a nice way of making sure your tests are always executed after a build. Though this isn't news to most developer 'dudes,' it surely made me all hot and steamy when I did it!
To do it you'll need the following:
- Visual Studio (no duh)
- Some sort of command line unit test app... like nunit console
- A new pair of pants after you see how rad this is.
So, you go here:
Visual Studio -> Project Properties -> Build Events
And add this line, pointing nunit-console to the DLL of your project:
"C:\Program Files\nunit\nunit-console.exe" "C:\SVN\Proj\trunk\ProjTestProj\bin\Release\ProjTestProj.dll"
And that's it! Get ready for the hotness!
But wait! There's more!
As an added bonus... I add this line before the line above...
copy /Y "$(ProjectDir)Web.config" "C:\SVN\Proj\trunk\ProjTestProj\App.config"
This enables "Unit testing" (or more like expectation testing) of the Web.config file by copying it over to the Unit Test project as App.config. When this happens, you would be able to talk to it in your Test project via the ConfigurationManager. For example:
Heavy Metal Rock and Roll.