Setting up automatic test runs after compilation in VS2010

I lifted some scripts from the interwebs so that after every compilation in visual studio unit tests are automatically run.  I have been a long supporter of the TestDriven.Net addin and Resharper but I found auto running unit tests to be pretty freeing.  Here’s the code.

So after a successful build the tests are run. Using this method you can automate any visual studio command or add in, including TestDriven.net or the Resharper Test runner.

 

You can get the code from CodePaste

image

Related Articles:

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Eric Hexter

I am the CTO for QuarterSpot. I (co)Founded MvcContrib, Should, Solution Factory, and Pstrami open source projects. I have co-authored MVC 2 in Action, MVC3 in Action, and MVC 4 in Action. I co-founded online events like mvcConf, aspConf, and Community for MVC. I am also a Microsoft MVP in ASP.Net.
This entry was posted in .Net, agile, VS2010. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://blog.wekeroad.com Rob Conery

    If you use NUnit’s TestRunner you can go into Tools/Options and Assembly Reload (I think that’s what it’s called) and there’s a checkbox: Rerun last set of tests.

    The cool thing is that it doesn’t require code :) and runs when the assembly is compiled and reloaded….

  • Michael Steele

    If you are using NUnit, you can just add a build event to the VS project through the project properties screen. Use it to run nunit-console.exe with the name of the assembly as the argument and it outputs the results to the Output window on successful build.

  • http://chrisedwards.dreamhosters.com/ Chris Edwards

    I posted something last week along very similar lines. How to have Visual Studio automatically kick off a Persona CI sever to run your tests for you each time you build or test your code. Extreme Continuous Integration: A Personal CI Build For Visual Studio – Part 1

  • Markus Johansson

    Where do I put this code to get it to run? In Visual Studio? Where in VS?

  • Mike Vanderkley

    I tried to do this. However, your CodePaste link is broken. So I was only able to manually type up everything except what is in the “Automattically generated code, do not modify”. So my macro is still not working. Please let me know what i am missing.

  • Eric Hexter

    dang it looks like the snippets from the site were deleted.