A while ago I published a post on how to create a build definition for Team Foundation Server 2010 that only ran the tests that had been identified by Test Impact Analysis. This is useful if your tests take a very long time to run, or you have a huge amount of tests and want quick feedback for your intra day builds.
This will work on the Team Foundation Service build system also.
I have had a few requests to get this updated for 2012/2013 and so here it is.
Things to remember:-
The testing system is a little different now than in 2010. When you create your build from the custom xaml and choose the process parameters go to the Add/Edit Test Run section.
You need to make sure that you select the MSTest.exe Runner. Test Impact Analysis is only supported by MSTest so if you don’t change this it won’t work. Also make sure that you select a .testsettings file also.
Remember that periodically (perhaps every night) you need to run a build, and change the IsBaseLine run parameter from False to True. This is what collects a base line of Test Impact data to measure your changes against. This will run all of your tests. They must all pass to gather the impact data.
Here is example output from my build. Notice that it has run 2 tests and there is no impact data.
We now have our baseline.
Once you have that you can run the build with the defaults and if you have changed some code that impacts a test it should appear.
In my example I have changed some code that will impact one test, and re-run the build.
Notice that the build only ran one test this time. The Impacted Tests section shows me which test was impacted and if i click on the Test run i see this.
So the build correctly ran the single impacted test. One last improvement over 2010, if you click on the “1 code change(s)” link on the Build report in the Impacted Tests section you see this
A nice summary of what was changed (with a link to the changeset and code diff) and the method name was changed etc. Much better!
The xaml is here. Any questions let me know.