18

Have just started using Visual Studio Professional's built-in unit testing features, which as I understand, uses MS Test to run the tests.

The .trx file that the tests produce is xml, but was wondering if there was an easy way to convert this file into a more "manager-friendly" format?

My ultimate goal is to be able to automate the unit-testing and be able to produce a nice looking document that shows the tests run and how 100% of them passed :)

Chris
  • 6,761
  • 6
  • 52
  • 67
PaulStock
  • 11,053
  • 9
  • 49
  • 52

5 Answers5

9

Since this file is XML you could and should use xsl to transform it to another format. The IAmUnkown - blog has an entry about decoding/transforming the trx file into html.

You can also use .NetSpecExporter from Bekk to create nice reports. Their product also uses XSL, so you could probably steal it from the downloaded file and apply it with whatever xsl-application you want.

Espo
  • 41,399
  • 21
  • 132
  • 159
4

you can also try trx2html

Edwin de Koning
  • 14,209
  • 7
  • 56
  • 74
rido
  • 1,202
  • 1
  • 9
  • 13
  • Can we use this for TFS 2010 as an activity? – alice7 Nov 30 '11 at 16:24
  • @alice7 Yes, you can either use the InvokeProcess in the workflow or create a custom activity which I prefer the second method since I have full control of what I want to do. – Ekk Nov 29 '12 at 03:19
  • @alice7 I have tried with the trx2Excel but it is throwing Unhandled Exception: System.InvalidOperationException: A worksheet with this name already exists in the workbook : this error – Piyush Jiwane Aug 10 '20 at 05:13
3

If you need to validate the schema before parsing/transforming it, you can find the XSD file in the Visual Studio install dir (via http://blogs.msdn.com/b/dhopton/archive/2008/06/12/helpful-internals-of-trx-and-vsmdi-files.aspx):

Note, that the XSD schemas are available with all visual studio installs in the:

%VSINSTALLDIR%\xml\Schemas\vstst.xsd

file directory, along with many other schemas.

Nikita R.
  • 7,245
  • 3
  • 51
  • 62
3

If your are using VS2008 I also have an answer on IAmUnknown. Which updates the above answer which is based on VS 2005 trx format

here is a style sheet that creates a readable HTM file

<xsl:stylesheet version="2.0"  
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:t="http://microsoft.com/schemas/VisualStudio/TeamTest/2006"
                >

<xsl:template match="/">
  <html>
  <head>
        <style type="text/css">
            h2 {color: sienna}
            p {margin-left: 20px}
            .resultsHdrRow { font-face: arial; padding: 5px }
            .resultsRow { font-face: arial; padding: 5px }
            </style>
    </head>
  <body>
    <h2>Test Results</h2>
    <h3>Summary</h3>
        <ul>
            <li>Tests found:    <xsl:value-of select="t:TestRun/t:ResultSummary/t:Counters/@total"/></li>
            <li>Tests executed: <xsl:value-of select="t:TestRun/t:ResultSummary/t:Counters/@executed"/></li>
            <li>Tests passed:   <xsl:value-of select="t:TestRun/t:ResultSummary/t:Counters/@passed"/></li>
            <li>Tests Failed:   <xsl:value-of select="t:TestRun/t:ResultSummary/t:Counters/@failed"/></li>

        </ul>
    <table border="1" width="80%" >
        <tr  class="resultsHdrRow">
          <th align="left">Test</th>
          <th align="left">Outcome</th>
        </tr>
        <xsl:for-each select="/t:TestRun/t:Results/t:UnitTestResult" >
        <tr valign="top" class="resultsRow">
            <td width='30%'><xsl:value-of select="@testName"/></td>
            <td width='70%'>
              <Div>Message: <xsl:value-of select="t:Output/t:ErrorInfo/t:Message"/></Div>
              <br/>
              <Div>Stack: <xsl:value-of select="t:Output/t:ErrorInfo/t:StackTrace"/></Div>
               <br/>
              <Div>Console: <xsl:value-of select="t:Output/t:StdOut"/></Div>
            </td>
        </tr>
        </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>
Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
  • 1
    Do you know an activity in TFS 2010 which could be like this? – alice7 Nov 30 '11 at 16:24
  • This is nothing to do with TFS. Do you mean msbuild? You can create a AfterTest target and add the functionality therein. – Preet Sangha Dec 01 '11 at 04:37
  • @PreetSangha actually, TFS has a Build component, where build process templates are defined in XAML (Workflow Templates, so XOML technically) wherein an 'Activity' may be added. The question is if there is an 'Activity' in 'TFS Build' which could do this. Thus, alice7's question has everything to do with TFS and nothing to do with MSBuild. Doing this from MSBuild presumes the use of MSBuild, while likely, it's not required and also not necessarily part of a Build Process Template at all (such as CI process templates that execute against artifacts created by Build process templates.) – Shaun Wilson Feb 26 '16 at 19:25
  • @ShaunWilson you are assuming the version of TFS. This question was asked/answered in 2008 about mstest output. In TFS 2005/8 did have MSBUILD based build definitions. XAML based build definitions of windows workflow activities were in TFS 2012/13. If you jump further and now look at the latest version of TFS 2015, there are now JSON based build definitions but with legacy support for the old XAML definitions. Though you are correct that you can add customisation to any version to reformat these files there was never anything in TFS build that specifically did this task. – Preet Sangha Feb 27 '16 at 20:56
0

Recently I wrote one trx to html convertor which is python based, have a look https://github.com/avinash8526/Murgi

Avinash Agrawal
  • 1,038
  • 1
  • 11
  • 17
  • That sounded great, but it seems that .TRX format in VS2019 might have been changed lightly cause the tool doesn't work as flawlessly as it was supposed to - generated HTML looks correct in general, but no CSS styles have been applied because of one broken DOM selector in the page source. – Sevenate Dec 09 '19 at 23:01