TFS Build: Running Integration Unit Tests

If you’re doing a deployment out to a test server as part of your Continuous Integration build process, you may have some unit tests (or web/load tests) to run after the deployment. Since these tests are testing more than just an assembly, they can be considered integration tests.

This can easily be accomplished by modifying your TFSBuild.proj script. Start by overriding the AfterDropBuild or similar MSBuild target and calling the <TestToolsTask> with the correct parameters.

First of all, you’ll need to define the tests that you want to run. The simplest way is to create a Test List called “Integration Tests” that gets saved in your test metadata file (*.vsmdi).

<ItemGroup>

  <IntegrationTestList Include=”$(SolutionRoot)\src\MySolution.vsmdi”>

    <TestList>Integration Tests</TestList>

    <FlavorToBuild>Release</FlavorToBuild>

    <PlatformToBuild>Any CPU</PlatformToBuild>

  </IntegrationTestList>

</ItemGroup>

There are two additional properties that we need to set, they are the Platform and Flavor. The reason for this is that when MSTest.exe tries to publish the integration test results to TFS, it needs to know what platform/flavor build to build against. And since we are doing this in AfterDropBuild, the configuration information isn’t available.

If your application requires additional files, or extra test run settings, you will need to specify them with a Test Run Config file:

<PropertyGroup>

  <RunConfigFile>$(SolutionRoot)\src\MySolution.testrunconfig</RunConfigFile>

</PropertyGroup>

And finally we can override the AfterDropBuild target to run the test list:

<Target Name=”AfterDropBuild”>

  <!– Execute Integration tests against remote server. –>

  <TestToolsTask

    Condition=” ‘$(IsDesktopBuild)’!=’true’ and ‘%(IntegrationTestList.Identity)’!=””

    BuildFlavor=”%(IntegrationTestList.FlavorToBuild)”

    Platform=”%(IntegrationTestList.PlatformToBuild)”

    PublishServer=”$(TeamFoundationServerUrl)”

    PublishBuild=”$(BuildNumber)”

    SearchPathRoot=”$(OutDir)”

    PathToResultsFilesRoot=”$(TestResultsRoot)”

    MetaDataFile=”%(IntegrationTestList.Identity)”

    RunConfigFile=”$(RunConfigFile)”

    TestLists=”%(IntegrationTestList.TestList)”

    TeamProject=”$(TeamProject)”

    TestNames=”$(TestNames)”

    ContinueOnError=”true” />

</Target>

Now when you view the Team Build results, you will have two sets of Test Results published against the single build.

One Trackback

  1. By Team System News : VSTS Links - 05/20/2008 on May 21, 2008 at 2:46 pm

    [...] Grant Holliday on TFS Build: Running Integration Unit Tests. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*