Team Foundation Server Build – Only run impacted tests (updated for 2012 & 2013)

9/25/2013

 

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.

 

image

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.

image

Here is example output from my build.  Notice that it has run 2 tests and there is no impact data.

image

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.

 

image

 

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.

 

image

 

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

 

image

 

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.

9/25/2013

3 comments :

  1. Hi, Rob.

    Great article! Could you post the link to the xaml file again? Looks like it is broken (the 2010 version works fine)

    Thanks!

    ReplyDelete
  2. Hi,

    could you please post the link to the xaml file again?

    Thank you!

    ReplyDelete
  3. Hi,

    Template XAML download link is broken. Please upload XAML file again.

    For TFS 2013 build template I tried to follow step given for 2010 template but there are lot of difference in 2010 and 2013 process template, so need 2013 XAML file please.

    Thanks,
    Hazeq.

    ReplyDelete