Skip to content

Instantly share code, notes, and snippets.

@ScottGuymer
Created February 17, 2014 16:24
Show Gist options
  • Save ScottGuymer/9053803 to your computer and use it in GitHub Desktop.
Save ScottGuymer/9053803 to your computer and use it in GitHub Desktop.
MsBuild file to run multiple test projects through mstest and put results into a single file
<Project ToolsVersion="4.0" DefaultTarget="RunTests" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<results_file>./TestResults/results.trx</results_file>
</PropertyGroup>
<PropertyGroup>
<MsTestExePath Condition="'$(MsTestExePath)'==''">C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\MSTest.exe</MsTestExePath>
</PropertyGroup>
<ItemGroup>
<TestAssemblies Include=".\**\bin\**\*.Tests.dll" />
</ItemGroup>
<ItemGroup>
<ResultsFile Include="$(results_file)" />
</ItemGroup>
<Target Name="RunTests">
<Message Text="Found test assemblies: @(TestAssemblies)" />
<MakeDir Directories="./TestResults" />
<CallTarget Targets="RunMsTest" />
</Target>
<Target Name="RunMsTest" >
<Message Text="Running to results file: %(ResultsFile.Identity)" />
<PropertyGroup>
<MsTestCommand>"$(MsTestExePath)" @(TestAssemblies ->'/testcontainer:&quot;%(RecursiveDir)%(Filename)%(Extension)&quot; ', ' ') /resultsfile:TestResults\%(ResultsFile.Identity)</MsTestCommand>
</PropertyGroup>
<Message Text="Running command $(MsTestCommand)" />
<Exec Condition=" '@(TestAssemblies)' != ''" Command="$(MsTestCommand)" ContinueOnError="true">
<Output TaskParameter="ExitCode" ItemName="ErrorCode"/>
</Exec>
<Message Text="Tests complete" />
<Message Text="The exit code is $(ErrorCode)"/>
<Error Text="Error while executing MSTest" Condition="'$(ErrorCode)' != ''" />
<OnError ExecuteTargets="MessageErrorHandler"/>
</Target>
<Target Name="MessageErrorHandler">
<Message Text="An error has occurred while executing MSTest"/>
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment