Skip to content

Commit

Permalink
Merge pull request #3 from iansul/master
Browse files Browse the repository at this point in the history
[JENKINS-19360] - Fix for mstest problems with trx files genereated by vstest.console.exe
  • Loading branch information
nilleb committed Jan 6, 2015
2 parents e11a4dc + 7bcb7b5 commit 0f2aa07
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 39 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.400</version>
<version>1.420</version>
</parent>

<groupId>org.jvnet.hudson.plugins</groupId>
Expand Down
80 changes: 49 additions & 31 deletions src/main/resources/hudson/plugins/mstest/mstest-to-junit.xsl
@@ -1,35 +1,44 @@
<?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: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"/>
<testsuites>
<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[.='Failed']) + count(//b:UnitTestResult/@outcome[.='Failed'])" />
<xsl:variable name="numberSkipped" select="count(//a:UnitTestResult/@outcome[.!='Passed' and .!='Failed']) + count(//b:UnitTestResult/@outcome[.!='Passed' and .!='Failed'])" />
<xsl:variable name="numberOfFailures" select="count(//a:UnitTestResult/@outcome[.='Failed']) + count(//b:UnitTestResult/@outcome[.='Failed'])" />
<xsl:variable name="numberSkipped" select="count(//a:UnitTestResult/@outcome[.!='Passed' and .!='Failed']) + count(//b:UnitTestResult/@outcome[.!='Passed' and .!='Failed'])" />
<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="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: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}"
<xsl:variable name="className">
<xsl:choose>
<xsl:when test="contains(a:TestMethod/@className, ',')">
<xsl:value-of select="substring-before(a:TestMethod/@className, ',')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="a:TestMethod/@className"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<testcase classname="{$className}"
name="{$testName}"
time="{$duration_hours*3600 + $duration_minutes*60 + $duration_seconds }">

<xsl:if test="contains($outcome, 'Failed')">
<xsl:if test="contains($outcome, 'Failed')">
<failure>
MESSAGE:
<xsl:value-of select="$message" />
Expand All @@ -42,39 +51,48 @@ STACK TRACE:
</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="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_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="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: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, ',')"/>
<xsl:variable name="currentTestId" select="@id"/>
<xsl:if test="$currentTestId = $testId" >
<xsl:variable name="className">
<xsl:choose>
<xsl:when test="contains(b:TestMethod/@className, ',')">
<xsl:value-of select="substring-before(b:TestMethod/@className, ',')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="b:TestMethod/@className"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<testcase classname="{$className}"
name="{$testName}"
time="{$duration_hours*3600 + $duration_minutes*60 + $duration_seconds }">
name="{$testName}"
time="{$duration_hours*3600 + $duration_minutes*60 + $duration_seconds }">

<xsl:if test="contains($outcome, 'Failed')">
<xsl:if test="contains($outcome, 'Failed')">
<failure>
MESSAGE:
<xsl:value-of select="$message" />
+++++++++++++++++++
STACK TRACE:
<xsl:value-of select="$stacktrace" />
</failure>
</xsl:if>
</testcase>
</xsl:if>
</xsl:if>
</testcase>
</xsl:if>
</xsl:for-each>
</xsl:for-each>

</testsuite>
</testsuites>
</xsl:template>
Expand Down
24 changes: 17 additions & 7 deletions src/test/java/hudson/plugins/mstest/MSTestReportConverterTest.java
Expand Up @@ -15,10 +15,10 @@

/**
* Unit tests for MSTestReportConverter class
*
*
* @author Antonio Marques
*/
public class MSTestReportConverterTest {
public class MSTestReportConverterTest {
@Before
public void setUp() {
XMLUnit.setIgnoreWhitespace(true);
Expand All @@ -45,33 +45,43 @@ public void testConversionFourTestsTwoClasses() throws Exception {
Diff myDiff = new Diff(readXmlAsString("junit_mstest_4_tests_2_classes.xml"), myTransform);
assertTrue("XSL transformation did not work" + myDiff, myDiff.similar());
}

@Test
public void testConversionTwoTestsFromDifferentAssemblies() throws Exception {

Transform myTransform = new Transform(new InputSource(this.getClass().getResourceAsStream("mstest_2_tests_from_different_assemblies.trx")),
new InputSource(this.getClass().getResourceAsStream(MSTestReportConverter.MSTEST_TO_JUNIT_XSLFILE_STR)));

Diff myDiff = new Diff(readXmlAsString("junit_mstest_2_tests_from_different_assemblies.xml"), myTransform);
assertTrue("XSL transformation did not work" + myDiff, myDiff.similar());
}

@Test
public void testConversionMSTest2010Schema() throws Exception {

Transform myTransform = new Transform(new InputSource(this.getClass().getResourceAsStream("mstest_vs_2010.trx")),
new InputSource(this.getClass().getResourceAsStream(MSTestReportConverter.MSTEST_TO_JUNIT_XSLFILE_STR)));

Diff myDiff = new Diff(readXmlAsString("mstest_vs_2010.xml"), myTransform);
assertTrue("XSL transformation did not work" + myDiff, myDiff.similar());
}

@Test
public void testConversionMSTest2012Schema() throws Exception {

Transform myTransform = new Transform(new InputSource(this.getClass().getResourceAsStream("mstest_vs_2012.trx")),
new InputSource(this.getClass().getResourceAsStream(MSTestReportConverter.MSTEST_TO_JUNIT_XSLFILE_STR)));

Diff myDiff = new Diff(readXmlAsString("mstest_vs_2012.xml"), myTransform);
assertTrue("XSL transformation did not work" + myDiff, myDiff.similar());
}

@Test
public void testConversionTestsWithDurationLongerThanOneMinute() throws Exception {

Transform myTransform = new Transform(new InputSource(this.getClass().getResourceAsStream("mstest_more_than_one_minute_test.trx")),
new InputSource(this.getClass().getResourceAsStream(MSTestReportConverter.MSTEST_TO_JUNIT_XSLFILE_STR)));

Diff myDiff = new Diff(readXmlAsString("junit_mstest_more_than-one_minute_test.xml"), myTransform);
assertTrue("XSL transformation did not work" + myDiff, myDiff.similar());
}
Expand Down
47 changes: 47 additions & 0 deletions src/test/resources/hudson/plugins/mstest/mstest_vs_2012.trx
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestRun id="38b008d6-3feb-4123-8d87-5791a3cdce8d" name="Carlos@COMPUTADOR-4 2010-02-08 15:12:31" runUser="Computador-4\Carlos" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<TestSettings name="Local" id="b8541fa7-a682-4127-b2b6-be4a44224f53">
<Description>These are default test settings for a local test run.</Description>
<Deployment enabled="false" runDeploymentRoot="Carlos_COMPUTADOR-4 2010-02-08 15_12_31" />
<Execution>
<TestTypeSpecific />
<AgentRule name="Execution Agents">
</AgentRule>
</Execution>
</TestSettings>
<Times creation="2010-02-08T15:12:31.6930000-02:00" queuing="2010-02-08T15:12:35.8630000-02:00" start="2010-02-08T15:12:35.9910000-02:00" finish="2010-02-08T15:12:36.9830000-02:00" />
<ResultSummary outcome="Failed">
<Counters total="2" executed="2" passed="1" error="0" failed="1" timeout="0" aborted="0" inconclusive="0" passedButRunAborted="0" notRunnable="0" notExecuted="0" disconnected="0" warning="0" completed="0" inProgress="0" pending="0" />
</ResultSummary>
<TestDefinitions>
<UnitTest name="TestMethod1" storage="c:\users\carlos\documents\visual studio 2010\projects\testproject1\testproject1\bin\debug\testproject1.dll" id="59863143-3238-122e-4d8a-637b491cc755">
<Execution id="25893b49-65e3-4b43-b122-34f38945de36" />
<TestMethod codeBase="c:/users/carlos/documents/visual studio 2010/Projects/TestProject1/TestProject1/bin/Debug/TestProject1.DLL" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="TestProject1.UnitTest1" name="TestMethod1" />
</UnitTest>
<UnitTest name="TestMethod2" storage="c:\users\carlos\documents\visual studio 2010\projects\testproject1\testproject1\bin\debug\testproject1.dll" id="9381223e-8095-9777-a0c7-26043045171c">
<Execution id="58d9adb6-df78-4fa7-817f-b5c8ff64e98f" />
<TestMethod codeBase="c:/users/carlos/documents/visual studio 2010/Projects/TestProject1/TestProject1/bin/Debug/TestProject1.DLL" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="TestProject1.UnitTest1" name="TestMethod2" />
</UnitTest>
</TestDefinitions>
<TestLists>
<TestList name="Results Not in a List" id="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
<TestList name="All Loaded Results" id="19431567-8539-422a-85d7-44ee4e166bda" />
</TestLists>
<TestEntries>
<TestEntry testId="59863143-3238-122e-4d8a-637b491cc755" executionId="25893b49-65e3-4b43-b122-34f38945de36" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
<TestEntry testId="9381223e-8095-9777-a0c7-26043045171c" executionId="58d9adb6-df78-4fa7-817f-b5c8ff64e98f" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
</TestEntries>
<Results>
<UnitTestResult executionId="25893b49-65e3-4b43-b122-34f38945de36" testId="59863143-3238-122e-4d8a-637b491cc755" testName="TestMethod1" computerName="COMPUTADOR-4" duration="00:00:00.0181950" startTime="2010-02-08T15:12:36.1200000-02:00" endTime="2010-02-08T15:12:36.7810000-02:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="25893b49-65e3-4b43-b122-34f38945de36">
</UnitTestResult>
<UnitTestResult executionId="58d9adb6-df78-4fa7-817f-b5c8ff64e98f" testId="9381223e-8095-9777-a0c7-26043045171c" testName="TestMethod2" computerName="COMPUTADOR-4" duration="00:00:00.1018105" startTime="2010-02-08T15:12:36.7930000-02:00" endTime="2010-02-08T15:12:36.8980000-02:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Failed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="58d9adb6-df78-4fa7-817f-b5c8ff64e98f">
<Output>
<ErrorInfo>
<Message>Assert.Fail failed. </Message>
<StackTrace> at TestProject1.UnitTest1.TestMethod2() in c:\users\carlos\documents\visual studio 2010\Projects\TestProject1\TestProject1\UnitTest1.cs:line 71
</StackTrace>
</ErrorInfo>
</Output>
</UnitTestResult>
</Results>
</TestRun>
15 changes: 15 additions & 0 deletions src/test/resources/hudson/plugins/mstest/mstest_vs_2012.xml
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites xmlns:a="http://microsoft.com/schemas/VisualStudio/TeamTest/2006" xmlns:b="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<testsuite name="MSTestSuite" tests="2" time="0" failures="1" errors="0" skipped="0">
<testcase classname="TestProject1.UnitTest1" name="TestMethod1" time="0.018195" />
<testcase classname="TestProject1.UnitTest1" name="TestMethod2" time="0.1018105">
<failure>
MESSAGE:
Assert.Fail failed.
+++++++++++++++++++
STACK TRACE:
at TestProject1.UnitTest1.TestMethod2() in c:\users\carlos\documents\visual studio 2010\Projects\TestProject1\TestProject1\UnitTest1.cs:line 71
</failure>
</testcase>
</testsuite>
</testsuites>

0 comments on commit 0f2aa07

Please sign in to comment.