I got fed up with loading a command line MS Test output data (.trx file) into visual studio in order to see the the failed tests and their messages so with the help of a colleague we came up with a simple XSL transformation that turns the output of the MS test session into a piece of text or html. We use the text version to print out a summary, and the html version to show the errors (if any :-)

In order to incorporate it into the command line desktop build I used nxslt2 from xmllab.net. Which takes the trx file, the xsl stylesheet and the output on its command line e.g.

nxslt2.exe  testrun.trx trxformatter.xsl -o testrun.results.htm




The summary stylesheet just outputs how many test found, passed and failed, and the name of the trx file if any did fail (so you can interrogate easily in vs if you want).







   1: <xsl:stylesheet version="2.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >


   2:     <xsl:output method="text" />


   3:     <xsl:template match="/">


   4:         Test Results Summary : Codebase: <xsl:value-of select="Tests/TestRun/tests/value/codeBase"/>


   5:         <xsl:if test="(Tests/TestRun/result/executedTestCount - Tests/TestRun/result/passedTestCount) > 0">


   6:             Summary : Failed <xsl:value-of select="Tests/TestRun/result/executedTestCount - Tests/TestRun/result/passedTestCount"/> (Executed [<xsl:value-of select="Tests/TestRun/result/executedTestCount"/>], Found [<xsl:value-of select="Tests/TestRun/result/totalTestCount"/>], Passed [<xsl:value-of select="Tests/TestRun/result/passedTestCount"/>])


   7:             Results : <xsl:value-of select="Tests/TestRun/runConfig/runDeploymentRoot"/>.trx


   8:         </xsl:if> <xsl:if test="(Tests/TestRun/result/executedTestCount - Tests/TestRun/result/passedTestCount) = 0">


   9:             Summary : Passed (Executed [<xsl:value-of select="Tests/TestRun/result/executedTestCount"/>], Found [<xsl:value-of select="Tests/TestRun/result/totalTestCount"/>], Passed [<xsl:value-of select="Tests/TestRun/result/passedTestCount"/>])


  10:         </xsl:if>


  11:  


  12:     </xsl:template>


  13: </xsl:stylesheet>







and outputs a summary similar to :



























 



The error details stylesheet :



<?xml version="1.0" ?>
<
xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<
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>
<
xsl:for-each select="Tests/TestRun/result">
<
h3>Summary</h3>
<
ul>
<
li>
Tests found: <xsl:value-of select="totalTestCount"/>
</
li>
<
li>
Tests executed: <xsl:value-of select="executedTestCount"/>
</
li>
<
li>
Tests passed: <xsl:value-of select="passedTestCount"/>
</
li>
</
ul>
</
xsl:for-each>
<
table border="1" width="80%" >
<
tr class="resultsHdrRow">
<
th align="left">Test</th>
<
th align="left">Outcome</th>
</
tr>
<
xsl:for-each select="Tests/UnitTestResult">
<
tr valign="top" class="resultsRow">
<
td width='30%'>
<
xsl:value-of select="testName"/>
</
td>
<
td width='70%'>
<
Div>
Message: <xsl:value-of select="errorInfo/message"/>
</
Div>
<
br/>
<
Div>
Stack: <xsl:value-of select="errorInfo/stackTrace"/>
</
Div>
</
td>
</
tr>
</
xsl:for-each>
</
table>
</
body>
</
html>
</
xsl:template>

</
xsl:stylesheet>



creates the following HTML output



image



Note that the test name will of course be yours, and any messages and stack trace will appear in the



I'm aware that you can optimise the xsl but it works for me as is.

3

View comments

  1. Really nice, i need just the same. Thanks

    ReplyDelete
  2. Looks cool, but the link for nxslt2 download is broken. i have not been able to locate the proper file yet. you may want to see if you can update the link.
    Thanks!
    Sky

    ReplyDelete
  3. Looks cool, but the link for nxslt2 download is broken. i have not been able to locate the proper file yet. you may want to see if you can update the link.
    Thanks!
    Sky

    ReplyDelete

Just a small post so I don't forget how to do this.

This morning I decided that I had to do something that I've been putting off for weeks. The current code base I'm looking after has about 400+ C++ projects and over past the (20+) years these projects have accumulated a large amount of dross. One in particular is the number of left over project configurations that are no longer working or of any use.

I'm still a baby in the brave (new?) world of DVCS and Git in particular and we're currently moving our workflow from a homegrown customised solution using SVN, Mantis and JIRA to a git, gitflow and TFS one. Anyway I've been learning about Semantic Versioning using GitVersion when something weird popped up for me.

Right down to moaning again. I've been using Windows 10 for a few weeks now (yes I'm old and slow these days!) and have been getting used to the new UI. Anyway like most major upgrades from Microsoft, some things get moved around, some become easier but to my chagrin some get hidden or become much harder to user.

The setting that really got me was the Windows connect to VPN function.

Been a long time since I posted and I think I need to start again. So what better way than to tell you what I've been up. In 2011 I moved into the BI consultancy space. And it was like learning to program again. I had to learn new techniques (Data Warehousing), new databases technologies SQL Server Analysis Server, new languages (MDX, RDL), new forms of reporting but most important of all I learned about analytics and how why BI is so important.

After having played with a WP7 device for about 8 months, I now have to say it's not for me. There are two reasons.

Firstly my current phone was lent to me, and now has to be returned. But this is not the show stopper. I'd buy a new one tomorrow if it wasn't for the second reason. The main reason I'm giving up on the Windows Phone 7 is that I cannot find a way (that works for me) to back up my telephony data.
4

I found this this morning via reddit and I think it sums up what's being playing on  my mind for years. What motivates us as people who make machines do 'stuff'.
2

This just passed me by. What a great function to avoid writing some triggers. Which we all know aren’t guaranteed to always fire.
2

I’ve just returned from a month away and have discovered that my disk has gone north last week, making the sounds of a rather rubbish DeeJay.

Since I use virtual machines for a lot of the work I’ve been doing and these machines actually run from a separate disk – I‘ve been fairly lucky and have only lost my vs2008 environment – the vs2010 is in a VM.

The Resharper 4.5 splash screen during installation made me laugh today. I completely dig Resharper (though I prefer Refactor Pro) so don’t get me wrong. I just thought “Wow, that makes my code easier to understand”.
Logo
Logo
My Blog List
My Blog List
Old Postings
Moi
Moi
North Shore, Auckland, New Zealand
I'm a developer from the UK who's been in the biz since the mid 80's. Currently I'm in NZ and am loving my work for Iridium Technology. You can contact me easily on preet...sangha@gmail.com remember to remove the ... in the middle
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.