Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-10911] xUnit not detecting Ignored MSTest and NUnit Tests
Support skipped testcase for MSTest using Inconclusive value for outcome attribute of the UnitTestResult XML element.
  • Loading branch information
nfalco79 committed May 11, 2018
1 parent 0670b5c commit 9aaab6e
Show file tree
Hide file tree
Showing 14 changed files with 311 additions and 96 deletions.
@@ -1,32 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*******************************************************************************
* Copyright (c) 2009 Thales Corporate Services SAS *
* Author : Gregory Boissinot *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy *
* of this software and associated documentation files (the "Software"), to deal*
* in the Software without restriction, including without limitation the rights *
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,*
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *
* THE SOFTWARE. *
*******************************************************************************/
The MIT License (MIT)
Copyright (c) 2012, Gregory Boissinot, Falco Nikolas
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<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="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xunit="http://www.xunit.org"
xmlns:a="http://microsoft.com/schemas/VisualStudio/TeamTest/2006" xmlns:b="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">

<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:decimal-format decimal-separator="." grouping-separator=","/>

<xsl:function name="xunit:junit-time" as="xs:string">
<xsl:param name="value" as="xs:double?" />

<xsl:variable name="time" as="xs:double">
<xsl:value-of select="translate(string($value),',','.')" />
</xsl:variable>
<xsl:value-of select="format-number($time, '0.000')" />
</xsl:function>

<xsl:function name="xunit:is-empty" as="xs:boolean">
<xsl:param name="value" as="xs:string?" />
<xsl:value-of select="string($value) != ''" />
</xsl:function>

<xsl:template match="/">
<testsuites>
<xsl:variable name="buildName" select="//a:TestRun/@name"/>
Expand All @@ -35,7 +50,7 @@
<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'])"/>
select="count(//a:UnitTestResult/@outcome[.='Inconclusive']) + count(//b:UnitTestResult/@outcome[.='Inconclusive'])"/>
<testsuite name="MSTestSuite"
tests="{$numberOfTests}" time="0"
failures="{$numberOfFailures}" errors="0"
Expand All @@ -44,19 +59,20 @@
<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="duration_seconds" select="number(substring(@duration, 7))"/>
<xsl:variable name="duration_minutes" select="number(substring(@duration, 4,2 ))"/>
<xsl:variable name="duration_hours" select="number(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, ',')"/>
<xsl:variable name="time" select="$duration_hours*3600 + $duration_minutes*60 + $duration_seconds"/>
<testcase classname="{$className}"
name="{$testName}"
time="{$duration_hours*3600 + $duration_minutes*60 + $duration_seconds }">
time="{xunit:junit-time($time)}">

<xsl:if test="contains($outcome, 'Failed')">
<failure>
Expand All @@ -75,27 +91,38 @@
<xsl:for-each select="//b: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="duration_seconds" select="number(substring(@duration, 7))"/>
<xsl:variable name="duration_minutes" select="number(substring(@duration, 4,2 ))"/>
<xsl:variable name="duration_hours" select="number(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:for-each select="//b:UnitTest">
<xsl:variable name="currentExecutionId" select="b:Execution/@id"/>
<xsl:if test="$currentExecutionId = $executionId">
<xsl:variable name="className" select="substring-before(b:TestMethod/@className, ',')"/>
<xsl:variable name="time" select="$duration_hours*3600 + $duration_minutes*60 + $duration_seconds"/>
<testcase classname="{$className}"
name="{$testName}"
time="{$duration_hours*3600 + $duration_minutes*60 + $duration_seconds }">
time="{xunit:junit-time($time)}">

<xsl:if test="$outcome = 'Inconclusive'">
<skipped />
<system-out>
MESSAGE:
<xsl:value-of select="$message"/>
+++++++++++++++++++
STACK TRACE:
<xsl:value-of select="$stacktrace"/>
</system-out>
</xsl:if>
<xsl:if test="contains($outcome, 'Failed')">
<failure>
MESSAGE:
<xsl:value-of select="$message"/>
+++++++++++++++++++
STACK TRACE:
<xsl:value-of select="$stacktrace"/>
MESSAGE:
<xsl:value-of select="$message"/>
+++++++++++++++++++
STACK TRACE:
<xsl:value-of select="$stacktrace"/>
</failure>
</xsl:if>
</testcase>
Expand Down
89 changes: 45 additions & 44 deletions src/test/java/org/jenkinsci/plugins/xunit/types/MSTestTest.java
@@ -1,56 +1,57 @@
/*******************************************************************************
* Copyright (c) 2010 Thales Corporate Services SAS *
* Author : Gregory Boissinot *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy *
* of this software and associated documentation files (the "Software"), to deal*
* in the Software without restriction, including without limitation the rights *
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,*
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *
* THE SOFTWARE. *
*******************************************************************************/

/*
* The MIT License (MIT)
*
* Copyright (c) 2014, Gregory Boissinot, Falco Nikolas
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.jenkinsci.plugins.xunit.types;

import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class MSTestTest extends AbstractTest {

@Test
public void testTransformationCase1() throws Exception {
convertAndValidate(MSTest.class, "mstest/mstest_2_tests_1_class.trx", "mstest/junit_mstest_2_tests_1_class.xml");
}

@Test
public void testTransformationCase2() throws Exception {
convertAndValidate(MSTest.class, "mstest/mstest_2_tests_from_different_assemblies.trx", "mstest/junit_mstest_2_tests_from_different_assemblies.xml");
}

@Test
public void testTransformationCase3() throws Exception {
convertAndValidate(MSTest.class, "mstest/mstest_4_tests_2_classes.trx", "mstest/junit_mstest_4_tests_2_classes.xml");
@Parameters(name = "testcase{1}: {0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] { { "mstest_2_tests_1_class", 1 }, //
{ "mstest_2_tests_from_different_assemblies", 2 }, //
{ "mstest_4_tests_2_classes", 3 }, //
{ "mstest_vs_2010", 4 }, //
{ "mstest_more_than_one_minute_test", 5 }, //
{ "JENKINS-10911", 6 } //
});
}

@Test
public void testTransformationCase4() throws Exception {
convertAndValidate(MSTest.class, "mstest/mstest_vs_2010.trx", "mstest/junit_mstest_vs_2010.xml");
public MSTestTest(String testName, int testNumber) {
super(MSTest.class, resolveInput("mstest", testNumber), resolveOutput("mstest", testNumber));
}

@Override
@Test
public void testTransformationCase5() throws Exception {
convertAndValidate(MSTest.class, "mstest/mstest_more_than_one_minute_test.trx", "mstest/junit_mstest_more_than-one_minute_test.xml");
public void verifyXSLT() throws Exception {
super.verifyXSLT();
}
}

}
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="MSTestSuite" tests="2" time="0" failures="1" errors="0" skipped="0">
<testcase classname="FunctionsTest.FibonacciTest" name="CalculaFibonacci" time="0.0157226"/>
<testcase classname="FunctionsTest.FibonacciTest" name="CalculaFibonacci_2" time="0.1007273">
<testcase classname="FunctionsTest.FibonacciTest" name="CalculaFibonacci" time="0.016"/>
<testcase classname="FunctionsTest.FibonacciTest" name="CalculaFibonacci_2" time="0.101">
<failure>
MESSAGE:
Assert.AreEqual failed. Expected:&lt;2&gt;. Actual:&lt;1&gt;.
Expand Down
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="MSTestSuite" tests="2" time="0" failures="1" errors="0" skipped="0">
<testcase classname="GoodGuyTest.GoodGuyTest" name="TestYell" time="0.0437026">
<testcase classname="GoodGuyTest.GoodGuyTest" name="TestYell" time="0.044">
<failure>
MESSAGE:
Assert.AreEqual failed. Expected:&lt;lala!&gt;. Actual:&lt;Lele!!&gt;.
Expand All @@ -10,6 +10,6 @@
at GoodGuyTest.GoodGuyTest.TestYell() in C:\PostIt\MultipleTests\GoodGuyTest\GoodGuyTest.cs:line 16
</failure>
</testcase>
<testcase classname="ProjectNumberOneTest.BoringGuyTest" name="TestYell" time="0.0230074"/>
<testcase classname="ProjectNumberOneTest.BoringGuyTest" name="TestYell" time="0.023"/>
</testsuite>
</testsuites>
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="MSTestSuite" tests="4" time="0" failures="2" errors="0" skipped="0">
<testcase classname="FunctionsTest.FibonacciTest" name="CalculaFibonacci" time="0.0038577"/>
<testcase classname="FunctionsTest.FibonacciTest" name="CalculaFibonacci_2" time="0.035657">
<testcase classname="FunctionsTest.FibonacciTest" name="CalculaFibonacci" time="0.004"/>
<testcase classname="FunctionsTest.FibonacciTest" name="CalculaFibonacci_2" time="0.036">
<failure>
MESSAGE:
Assert.AreEqual failed. Expected:&lt;2&gt;. Actual:&lt;1&gt;.
Expand All @@ -12,8 +12,8 @@
E:\Koiti\Dev\GitHudsonTest\FunctionsTest\FibonacciTest.cs:line 72
</failure>
</testcase>
<testcase classname="FunctionsTest.SpecialCharRemoverTest" name="RemoveSpecialChar" time="0.0010439"/>
<testcase classname="FunctionsTest.SpecialCharRemoverTest" name="REmoveSpecialChar2" time="0.000883">
<testcase classname="FunctionsTest.SpecialCharRemoverTest" name="RemoveSpecialChar" time="0.001"/>
<testcase classname="FunctionsTest.SpecialCharRemoverTest" name="REmoveSpecialChar2" time="0.001">
<failure>
MESSAGE:
Assert.AreEqual failed. Expected:&lt;pao&gt;. Actual:&lt;paao&gt;.
Expand Down
Expand Up @@ -2,8 +2,8 @@
<testsuites
>
<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">
<testcase classname="TestProject1.UnitTest1" name="TestMethod1" time="0.018"/>
<testcase classname="TestProject1.UnitTest1" name="TestMethod2" time="0.102">
<failure>
MESSAGE:
Assert.Fail failed.
Expand Down
Expand Up @@ -2,8 +2,8 @@
<testsuites
>
<testsuite name="MSTestSuite" tests="2" time="0" failures="1" errors="0" skipped="0">
<testcase classname="FunctionsTest.FibonacciTest" name="CalculaFibonacci" time="130.0157226"/>
<testcase classname="FunctionsTest.FibonacciTest" name="CalculaFibonacci_2" time="0.1007273">
<testcase classname="FunctionsTest.FibonacciTest" name="CalculaFibonacci" time="130.016"/>
<testcase classname="FunctionsTest.FibonacciTest" name="CalculaFibonacci_2" time="0.101">
<failure>
MESSAGE:
Assert.AreEqual failed. Expected:&lt;2&gt;. Actual:&lt;1&gt;.
Expand Down

0 comments on commit 9aaab6e

Please sign in to comment.