Skip to content

Commit

Permalink
[JENKINS-18265] xsl now includes errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivo Bellin Salarin committed Mar 11, 2015
1 parent 3d2fe9d commit b96ff71
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/main/resources/hudson/plugins/mstest/mstest-to-junit.xsl
@@ -1,13 +1,15 @@
<?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: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>
<xsl:variable name="buildName" select="/a:TestRun/@name or /b:TestRun/@name"/>
<xsl:variable name="numberOfTests" select="count(/a:TestRun/a:ResultSummary/Counters/@total) + count(/a:TestRun/a:ResultSummary/Counters/@total)"/>
<xsl:variable name="numberOfFailures" select="count(/a:TestRun/a:ResultSummary/a:Counters/@failed)" />
<xsl:variable name="numberOfErrors" select="count(/a:TestRun/a:ResultSummary/a:Counters/@errors)" />
<xsl:variable name="numberSkipped" select="count(/a:TestRun/a:ResultSummary/Counters/@notRunnable)" />
<xsl:variable name="numberOfTests" select="sum(/a:TestRun/a:ResultSummary/a:Counters/@total | /b:TestRun/b:ResultSummary/b:Counters/@total)"/>
<xsl:variable name="numberOfFailures" select="sum(/a:TestRun/a:ResultSummary/a:Counters/@failed | /b:TestRun/b:ResultSummary/b:Counters/@failed)" />
<xsl:variable name="numberOfErrors" select="sum(/a:TestRun/a:ResultSummary/a:Counters/@error | /b:TestRun/b:ResultSummary/b:Counters/@error)" />
<xsl:variable name="numberSkipped" select="sum(/a:TestRun/a:ResultSummary/a:Counters/@notRunnable | /b:TestRun/b:ResultSummary/b:Counters/@notRunnable)" />
<testsuite name="MSTestSuite"
tests="{$numberOfTests}" time="0"
failures="{$numberOfFailures}" errors="{$numberOfErrors}"
Expand All @@ -16,6 +18,7 @@
<xsl:for-each select="//a:UnitTestResult">
<xsl:variable name="testName" select="@testName"/>
<xsl:variable name="executionId" select="@executionId"/>
<xsl:variable name="duration" select="@duration"/>
<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)"/>
Expand All @@ -36,9 +39,12 @@
</xsl:choose>
</xsl:variable>
<testcase classname="{$className}"
name="{$testName}"
time="{$duration_hours*3600 + $duration_minutes*60 + $duration_seconds }">

name="{$testName}">
<xsl:if test="$duration">
<xsl:attribute name="time">
<xsl:value-of select="$duration_hours*3600 + $duration_minutes*60 + $duration_seconds"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="contains($outcome, 'Failed')">
<failure>
MESSAGE:
Expand All @@ -57,6 +63,7 @@ STACK TRACE:
<xsl:variable name="testName" select="@testName"/>
<xsl:variable name="executionId" select="@executionId"/>
<xsl:variable name="testId" select="@testId"/>
<xsl:variable name="duration" select="@duration"/>
<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)"/>
Expand All @@ -78,7 +85,12 @@ STACK TRACE:
</xsl:variable>
<testcase classname="{$className}"
name="{$testName}"
time="{$duration_hours*3600 + $duration_minutes*60 + $duration_seconds }">
>
<xsl:if test="$duration">
<xsl:attribute name="time">
<xsl:value-of select="$duration_hours*3600 + $duration_minutes*60 + $duration_seconds"/>
</xsl:attribute>
</xsl:if>

<xsl:if test="contains($outcome, 'Failed')">
<failure>
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/hudson/plugins/mstest/MSTestReportConverterTest.java
Expand Up @@ -76,6 +76,16 @@ public void testConversionMSTest2012Schema() throws Exception {
assertTrue("XSL transformation did not work" + myDiff, myDiff.similar());
}

@Test
public void testErrorCount() throws Exception {

Transform myTransform = new Transform(new InputSource(this.getClass().getResourceAsStream("kozl-unit-tests-missing.trx")),
new InputSource(this.getClass().getResourceAsStream(MSTestReportConverter.MSTEST_TO_JUNIT_XSLFILE_STR)));

Diff myDiff = new Diff(readXmlAsString("kozl-unit-test-missing.xml"), myTransform);
assertTrue("XSL transformation did not work" + myDiff, myDiff.similar());
}

@Test
public void testConversionTestsWithDurationLongerThanOneMinute() throws Exception {

Expand Down
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites xmlns:b="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" xmlns:a="http://microsoft.com/schemas/VisualStudio/TeamTest/2006">
<testsuite name="MSTestSuite" tests="3" time="0" failures="0" errors="3" skipped="0">
<testcase classname="LindbergCorp.StringFileTranslator.Test.TranslatorTests" name="TestConversion"/>
<testcase classname="LindbergCorp.StringFileTranslator.Test.TranslatorTests" name="TestConversionFrench"/>
<testcase classname="LindbergCorp.StringFileTranslator.Test.TranslatorTests" name="TestFileNotFound"/>
</testsuite>
</testsuites>

0 comments on commit b96ff71

Please sign in to comment.