Skip to content

Instantly share code, notes, and snippets.

@vansha
Last active December 16, 2015 06:49
Show Gist options
  • Save vansha/5394393 to your computer and use it in GitHub Desktop.
Save vansha/5394393 to your computer and use it in GitHub Desktop.
Customized mstest-to-junit xsl we use to show MSTest results in Jenkins. Original xsl is taken from mstest plugin source - https://github.com/jenkinsci/mstest-plugin/blob/master/src/main/resources/hudson/plugins/mstest/mstest-to-junit.xsl Customizations: * Show tests with 'Timeout' outcome as failed one. * Tests with 'NotExecuted' and 'Aborted' …
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a ="http://microsoft.com/schemas/VisualStudio/TeamTest/2006" xmlns:b ="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" >
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<testsuites>
<!-- MSTest outcomes: -->
<!-- total="218" executed="53" passed="52" error="0" failed="0" timeout="0" aborted="0" inconclusive="1" passedButRunAborted="0" notRunnable="0" notExecuted="165" disconnected="0" warning="0" completed="0" inProgress="0" pending="0" -->
<xsl:variable name="buildName" select="//a:TestRun/@name"/>
<xsl:variable name="numberOfTests" select="count(//a:UnitTestResult/@outcome) + count(//b:UnitTestResult/@outcome)"/>
<xsl:variable name="numberOfFailures" select="count(//a:UnitTestResult/@outcome[.!='Passed' and .!='Inconclusive' and .!='NotExecuted' and .!='Aborted']) + count(//b:UnitTestResult/@outcome[.!='Passed' and .!='Inconclusive' and .!='NotExecuted' and .!='Aborted'])" />
<xsl:variable name="numberSkipped" select="count(//a:UnitTestResult/@outcome[.='Inconclusive' or .='NotExecuted' or .='Aborted']) + count(//b:UnitTestResult/@outcome[.='Inconclusive' or .='NotExecuted' or .='Aborted'])" />
<testsuite name="MSTestSuite"
tests="{$numberOfTests}" time="0"
failures="{$numberOfFailures}" errors="0"
skipped="{$numberSkipped}">
<xsl:for-each select="//a:UnitTestResult">
<xsl:variable name="testName" select="@testName"/>
<xsl:variable name="executionId" select="@executionId"/>
<xsl:variable name="duration_seconds" select="substring(@duration, 7)"/>
<xsl:variable name="duration_minutes" select="substring(@duration, 4,2 )"/>
<xsl:variable name="duration_hours" select="substring(@duration, 1, 2)"/>
<xsl:variable name="outcome" select="@outcome"/>
<xsl:variable name="message" select="a:Output/a:ErrorInfo/a:Message"/>
<xsl:variable name="stacktrace" select="a:Output/a:ErrorInfo/a:StackTrace"/>
<xsl:variable name="stdout" select="a:Output/a:StdOut"/>
<xsl:for-each select="//a:UnitTest">
<xsl:variable name="currentExecutionId" select="a:Execution/@id"/>
<xsl:if test="$currentExecutionId = $executionId" >
<xsl:variable name="className" select="substring-before(a:TestMethod/@className, ',')"/>
<testcase classname="{$className}"
name="{$testName}"
time="{$duration_hours*3600 + $duration_minutes*60 + $duration_seconds }">
<xsl:if test="$outcome != 'Passed' and $outcome != 'Inconclusive' and $outcome != 'NotExecuted' and $outcome != 'Aborted'">
<failure>
MESSAGE:
<xsl:value-of select="$message" />
+++++++++++++++++++
STACK TRACE:
<xsl:value-of select="$stacktrace" />
</failure>
</xsl:if>
<xsl:if test="contains($outcome, 'Inconclusive') or contains($outcome, 'NotExecuted') or contains($outcome, 'Aborted')">
<skipped>
MESSAGE:
<xsl:value-of select="$message" />
+++++++++++++++++++
STACK TRACE:
<xsl:value-of select="$stacktrace" />
</skipped>
</xsl:if>
<xsl:if test="$stdout != ''">
<system-out>
SYSTEM OUTPUT:
<xsl:value-of select="$stdout" />
</system-out>
</xsl:if>
</testcase>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
<xsl:for-each select="//b:UnitTestResult">
<xsl:variable name="testName" select="@testName"/>
<xsl:variable name="executionId" select="@executionId"/>
<xsl:variable name="testId" select="@testId"/>
<xsl:variable name="duration_seconds" select="substring(@duration, 7)"/>
<xsl:variable name="duration_minutes" select="substring(@duration, 4,2 )"/>
<xsl:variable name="duration_hours" select="substring(@duration, 1, 2)"/>
<xsl:variable name="outcome" select="@outcome"/>
<xsl:variable name="message" select="b:Output/b:ErrorInfo/b:Message"/>
<xsl:variable name="stacktrace" select="b:Output/b:ErrorInfo/b:StackTrace"/>
<xsl:variable name="stdout" select="b:Output/b:StdOut"/>
<xsl:for-each select="//b:UnitTest">
<xsl:variable name="currentTestId" select="@id"/>
<xsl:if test="$currentTestId = $testId" >
<xsl:variable name="className" select="substring-before(b:TestMethod/@className, ',')"/>
<testcase classname="{$className}"
name="{$testName}"
time="{$duration_hours*3600 + $duration_minutes*60 + $duration_seconds }">
<xsl:if test="$outcome != 'Passed' and $outcome != 'Inconclusive' and $outcome != 'NotExecuted'">
<failure>
<xsl:if test="$message != ''">
MESSAGE:
<xsl:value-of select="$message" />
+++++++++++++++++++
</xsl:if>
<xsl:if test="$stacktrace != ''">
STACK TRACE:
<xsl:value-of select="$stacktrace" />
</xsl:if>
</failure>
</xsl:if>
<xsl:if test="contains($outcome, 'Inconclusive') or contains($outcome, 'NotExecuted') or contains($outcome, 'Aborted')">
<skipped>
<xsl:if test="$message != ''">
MESSAGE:
<xsl:value-of select="$message" />
+++++++++++++++++++
</xsl:if>
<xsl:if test="$stacktrace != ''">
STACK TRACE:
<xsl:value-of select="$stacktrace" />
</xsl:if>
</skipped>
</xsl:if>
<xsl:if test="$stdout != ''">
<system-out>
SYSTEM OUTPUT:
<xsl:value-of select="$stdout" />
</system-out>
</xsl:if>
</testcase>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</testsuite>
</testsuites>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment