Derik Whittaker



Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
Adding MSTest results (.trx) files to your TeamCity build results

As I am building out our CI environment with TeamCity (man, this is a great product) I finally had to tackle something that I have been putting off for the past few weeks.  Adding the tests results to TeamCity from our various components which use MSTest.  I have already added NUnit results, as that is done for you out of the box with TeamCity.  Now before you ask ‘Why are you using both MSTest and NUnit’?  We simple.  Most our older tests are done with MSTest (god, I really, really hate MSTests – More here) and most our newer (less than 6 months old) code is in NUnit.

I really thought that adding MSTests would be a pain, but as it turned out it was not.  I searched Jetbrains knowledge base and found this posting which talked about what  you needed to do to add MSTest results to your build.

Basically you only need to add this line to your build (assuming NAnt here) file.

##teamcity[importData id='mstest' file='<path to .trx file>']

When I say add it, I simply mean doing a echo of this information.  This is possible because TeamCity watches the standard output stream for various commands, and this is one of the commands you can use.

Here is how I added this to my build file:

<target name="" >
  <property name="" value="${tests.output.dir}/testResults.trx" />
  <if test="${file::exists(}">
    <echo message="Deleting old test run file ${}" />
    <delete file="${}" />
  <exec program="MSTest.exe"
        commandline="/testcontainer:${build.dir}${communication.tests.file} /testcontainer:${build.dir}${httpImportService.tests.file} /testcontainer:${build.dir}${messagesCore.tests.file} /testcontainer:${build.dir}${messageHandler.tests.file} /resultsfile:${tests.output.dir}/testResults.trx"
        basedir="C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE"

  <!--- This is the needed line for TeamCity -->
  <echo message="##teamcity[importData id='mstest' file='…path to output….\Output_AutomatedBuild\Output_UnitTests\testResults.trx']" />

As you can see this is real easy.  Once you have this in your build file simply re-run your build in TeamCity and check your build results.  If you did every thing correct you should have a ‘Test’ tab.  If something went wrong check your output logs as it should tell you what blew up.

Hope this helps someone.

Till next time,

[--- Check out ---]

Posted 12-20-2008 9:39 AM by Derik Whittaker



Dew Drop - Weekend Edition - December 20-21, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - Weekend Edition - December 20-21, 2008 | Alvin Ashcraft's Morning Dew
on 12-20-2008 9:08 PM

Pingback from  Dew Drop - Weekend Edition - December 20-21, 2008 | Alvin Ashcraft's Morning Dew wrote Simple how to on adding MSTest results files to TeamCIty
on 12-21-2008 9:25 PM

You've been kicked (a good thing) - Trackback from

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)