Skip to content

Commit

Permalink
[JENKINS-10911] xUnit not detecting Ignored MSTest and NUnit Tests
Browse files Browse the repository at this point in the history
Fix skipped testcase in NUnit and NUnit3 when there are failed testcase before. generalfailure variable in XSL seems brokes the dom navigation.
  • Loading branch information
nfalco79 committed May 11, 2018
1 parent 10d5280 commit 0670b5c
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 87 deletions.
Expand Up @@ -22,9 +22,29 @@ 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">
<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">
<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:if-empty" as="xs:string">
<xsl:param name="value" as="xs:string?" />
<xsl:param name="default" as="xs:anyAtomicType" />
<xsl:value-of select="if (string($value) != '') then string($value) else $default" />
</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="/test-results">
<testsuites>
Expand Down Expand Up @@ -59,7 +79,7 @@ THE SOFTWARE.
>
<xsl:if test="@time!=''">
<xsl:attribute name="time">
<xsl:value-of select="@time"/>
<xsl:value-of select="xunit:junit-time(@time)"/>
</xsl:attribute>
</xsl:if>
<xsl:for-each select="*/test-case">
Expand All @@ -80,42 +100,44 @@ THE SOFTWARE.
name="{$testcaseName}">
<xsl:if test="@time!=''">
<xsl:attribute name="time">
<xsl:value-of select="@time"/>
<xsl:value-of select="xunit:junit-time(@time)"/>
</xsl:attribute>
</xsl:if>

<xsl:variable name="generalfailure"
select="./failure"/>
<xsl:if test="@executed='False'">
<skipped>
<xsl:if test="xunit:is-empty(./reason/message)">
<xsl:attribute name="message">
<xsl:value-of select="./reason/message"/>
</xsl:attribute>
</xsl:if>
</skipped>
</xsl:if>

<xsl:variable name="generalfailure" select="./failure"/>

<xsl:if test="./failure">
<xsl:variable name="failstack"
select="count(./failure/stack-trace/*) + count(./failure/stack-trace/text())"/>
<failure>
<xsl:choose>
<xsl:when test="$failstack &gt; 0 or not($generalfailure)">
MESSAGE:
<xsl:value-of select="./failure/message"/>
+++++++++++++++++++
STACK TRACE:
<xsl:value-of select="./failure/stack-trace"/>
MESSAGE:
<xsl:value-of select="./failure/message"/>
+++++++++++++++++++
STACK TRACE:
<xsl:value-of select="./failure/stack-trace"/>
</xsl:when>
<xsl:otherwise>
MESSAGE:
<xsl:value-of select="$generalfailure/message"/>
+++++++++++++++++++
STACK TRACE:
<xsl:value-of select="$generalfailure/stack-trace"/>
MESSAGE:
<xsl:value-of select="$generalfailure/message"/>
+++++++++++++++++++
STACK TRACE:
<xsl:value-of select="$generalfailure/stack-trace"/>
</xsl:otherwise>
</xsl:choose>
</failure>
</xsl:if>
<xsl:if test="@executed='False'">
<skipped>
<xsl:attribute name="message">
<xsl:value-of select="./reason/message"/>
</xsl:attribute>
</skipped>
</xsl:if>
</testcase>
</xsl:for-each>
</testsuite>
Expand Down
Expand Up @@ -2,7 +2,7 @@
<!--
The MIT License (MIT)
Copyright (c) 2017, Alex Schwantes
Copyright (c) 2017, Alex Schwantes, Nikolas Falco
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -35,6 +35,11 @@ THE SOFTWARE.
<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="/test-run">
<!--<xsl:variable name="hostname" select="./environment/@machine-name"/>-->
<testsuites>
Expand All @@ -57,6 +62,19 @@ THE SOFTWARE.
</xsl:attribute>
</xsl:if>

<xsl:if test="@result='Skipped' or @result='Inconclusive'" >
<skipped>
<xsl:if test="xunit:is-empty(./reason/message)">
<xsl:attribute name="message">
<xsl:value-of select="./reason/message"/>
</xsl:attribute>
</xsl:if>
</skipped>
<system-out>
<xsl:value-of select="./output" />
</system-out>
</xsl:if>

<xsl:variable name="generalfailure" select="./failure" />

<xsl:if test="./failure">
Expand Down Expand Up @@ -86,13 +104,6 @@ OUTPUT:
</xsl:choose>
</failure>
</xsl:if>
<xsl:if test="@result='Skipped' or @result='Inconclusive'" >
<skipped/>
<system-out>
<xsl:value-of select="./reason/message"/>
<xsl:value-of select="./output" />
</system-out>
</xsl:if>
</testcase>
</xsl:for-each>
</testsuite>
Expand Down
48 changes: 24 additions & 24 deletions src/test/java/org/jenkinsci/plugins/xunit/types/NUnit3Test.java
@@ -1,26 +1,26 @@
/*******************************************************************************
* 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) 2017, Alex Schwantes, 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 java.util.Arrays;
Expand All @@ -34,7 +34,7 @@
@RunWith(Parameterized.class)
public class NUnit3Test extends AbstractTest {

@Parameters(name = "{0}")
@Parameters(name = "testcase{1}: {0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] { { "simple transformation", 1 }, //
{ "test transformed of ignored", 2 } //
Expand Down
51 changes: 26 additions & 25 deletions src/test/java/org/jenkinsci/plugins/xunit/types/NUnitTest.java
@@ -1,26 +1,26 @@
/*******************************************************************************
* 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) 2010, Gregory Boissinot, Nikolas Falco
*
* 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 java.util.Arrays;
Expand All @@ -34,14 +34,15 @@
@RunWith(Parameterized.class)
public class NUnitTest extends AbstractTest {

@Parameters(name = "{0}")
@Parameters(name = "testcase{1}: {0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] { { "simple transformation", 1 }, //
{ "failures transformation", 2 }, //
{ "MultiNamespace transformation", 3 }, //
{ "test transformed of ignored", 4 }, //
{ "JENKINS-1077", 5 }, //
{ "JENKINS-8492", 6 }
{ "JENKINS-8492", 6 }, //
{ "JENKINS-10911 skipped are ignored when failure is present before", 7 }
});
}

Expand Down
Expand Up @@ -2,7 +2,7 @@
<testsuites>
<testsuite name="UnitTests.OtherMainClassTest" tests="3" time="0.001" failures="0" errors="0" skipped="2">
<testcase classname="UnitTests.OtherMainClassTest" name="TestIgnored">
<skipped message=""/>
<skipped />
</testcase>
<testcase classname="UnitTests.OtherMainClassTest" name="TestIgnoredWithText">
<skipped message="Dont do this"/>
Expand Down
Expand Up @@ -4,9 +4,8 @@
<testcase classname="AdministrationPasswordTest" name="testChangePasswordFailEmptyForm" time="5.065"/>
<testcase classname="AdministrationPasswordTest" name="testChangePasswordFailOldPasswordKO" time="5.066"/>
<testcase classname="AdministrationPasswordTest" name="testChangePasswordFailNewPasswordTooShort" time="5.049"/>
<testcase classname="AdministrationPasswordTest" name="testChangePasswordFailNewPasswordNotRepeated"
time="5.05"/>
<testcase classname="AdministrationPasswordTest" name="testChangePasswordFailNewPasswordNotRepeated" time="5.050"/>
<testcase classname="AdministrationPasswordTest" name="testChangePasswordFailNewPasswordKO" time="5.066"/>
<testcase classname="AdministrationPasswordTest" name="testChangePassword" time="10.1"/>
<testcase classname="AdministrationPasswordTest" name="testChangePassword" time="10.100"/>
</testsuite>
</testsuites>

0 comments on commit 0670b5c

Please sign in to comment.