DotNetSurfers

Latish Sehgal's Blog

Using Test Impact Analysis in Visual Studio 2010

A tweet this morning from David O’Hara about wanting something on the lines of Autospec for Visual Studio motivated me to look into the Test Impact Analysis feature in Visual Studio 2010. Test Impact Analysis allows you to see what unit tests have been impacted by your latest code changes. This means that you need to run only the affected tests rather than the whole test suite to ensure that you have not made any breaking changes. This is clearly a big productivity win, especially if you have a big test suite.

I created a small Calculator Class and corresponding unit tests to work with. Here’s what you need to do to get started with Test Impact Analysis.

  1. Open your project in Visual Studio 2010 and open “Test Impact View” window (Test->Windows->Test Impact View). You should see something like this.

  2. Enable test impact data collection by clicking on the link in the “Test Impact View” window. You can also do the same by going into Test->Edit Test Settings->Test Settings->Data And Diagnostics->Test Impact.

  3. To generate baseline data, you need to rebuild your solution and run all tests in your test projects. You can do this using the “Test View Window”. Your “Test Impact Window” should now look like this.

  4. Make code changes that you are working on. Since I am just testing here, I modify my Add() method to do multiplication instead of additon. Now when I Save the code and Rebuild the project, the “Test Impact Window” automatically updates to show what tests need to be re-run. In this case, I need to re-run my “AddTest”. I do so using “Run Tests” link in the “Test Impact View” or the keyboard shortcut Ctrl +R,Y.

  5. Running “AddTest” causes it to fail since I introduced a bug in the last step.

  6. Since my test failed, it still shows up under “Impacted Tests”. I now fix my Add() method, rebuild my project and rerun the unit test. My unit test passes and the “Test Impact View” becomes empty again, indicating that my code is in good shape and safe to check in.

While this is not as powerful as running affected unit tests automatically in the background like AutoSpec does for Ruby, it’s defintely a step in the right direction. I can totally see this becoming a part of my workflow.

A couple of other things

  • Since Visual Studio only recognizes MSTest unit tests, I am not sure if this would work with other frameworks like NUnit. If you know of a way to do so, please leave a comment.
  • The Test Impact Analysis feature is available in Premium and Ultimate versions but not in the Professional version. See this for feature comparison between different versions.
  • I tested this with Beta 2 of Visual Studio 2010.

Comments