Question

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 :)

Was it helpful?

Solution

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.

OTHER TIPS

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>

you can also try trx2html

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top