After migrating from TFS 2008 to TFS 2010 the way test results are handled has changed.
Szenario
When running tests a whole system szenario is setup which means that a lot of files and additional content is copied to the test run folder
Issue
When test results are published to TFS 2010 the content of the test run folder is also published. This causes the TFS databases to grow rapidly
Solution
1. Disable publishing test result
2. Cleanup test result folders before publishing the test results
3. Publish test results manually
HowTo: Disable publishing test results
Simply set a specific MSBuild property that is used by the TestToolsTask
<PublishTestResults>false</PublishTestResults>
TFS 2010: Cleanup test result folders before publishing the test results
The test run’s execution folder is the out directory. From that directory we drop everything except the instrumented binaries and debug symbols. This allows us to still retrieve code coverage data. Dropping all other files will prevent the test execution when we open the test results from the build summary.
<CreateItem Include="$(TestResultsRoot)\**\Out\*.instr.pdb">
<Output TaskParameter="Include" ItemName="InstrumentedDebugSymbolFiles"/>
</CreateItem>
<RegExReplace Input="@(InstrumentedDebugSymbolFiles)" Expression="\.instr\.pdb$" Replacement=".exe">
<Output ItemName="InstrumentedExeAssemblies" TaskParameter="Output" />
</RegExReplace>
<RegExReplace Input="@(InstrumentedDebugSymbolFiles)" Expression="\.instr\.pdb$" Replacement=".dll">
<Output ItemName="InstrumentedDllAssemblies" TaskParameter="Output" />
</RegExReplace>
<CreateItem Include="$(TestResultsRoot)\**\Out\**\*" exclude="@(InstrumentedExeAssemblies);@(InstrumentedDllAssemblies);@(InstrumentedDebugSymbolFiles)">
<Output TaskParameter="Include" ItemName="TestOutputToDelete"/>
</CreateItem>
<Delete Files="@(TestOutputToDelete)" />
HowTo: Publish test results manually
In order to publish the test result we just use the publishing feature of mstest. We identify all trx files and publish them one by one. For ease of use we do not determine the MSTest.exe path dynamically. We just defined a property that keeps the path.
<MSTestCommand>$(ProgramFiles)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe</MSTestCommand>
Using this property and the information from the current build we can easily publish the results as follows:
<!– Get all trx files for publishing –>
<CreateItem Include="$(TestResultsRoot)\**\*.trx">
<Output TaskParameter="Include" ItemName="TestResultFiles"/>
</CreateItem>
<!– Now publish all trx files –>
<Exec Command=""$(MSTestCommand)" /publish:"$(TeamFoundationServerUrl)" /publishbuild:"$(BuildUri)" /PublishResultsFile:"%(TestResultFiles.Identity)" /teamproject:"$(TeamProject)" /platform:"Mixed Platforms" /flavor:"Debug"" ContinueOnError="true" />
Please also notice that we do not determine the build configuration (platform and flavor) dynamically. We “hard-coded” it.