我正在使用xUnit Jenkins插件以XML格式(xunit.xml)打印slash提供的测试结果:
<testsuite errors="0" failures="1" hostname="macbook-pro.local" name="slash-suite" skipped="0" tests="2" time="0" timestamp="2018-10-03T13:25:05">
<testcase classname="bla" name="test.py:test_a" time="0">
<failure message="AssertionError: assert False" type="failure" />
</testcase>
<testcase classname="" name="test.py:test_b" time="0" />
</testsuite>
为了处理此XML,我使用了自定义工具来处理不受支持的格式。
这需要我提供一个XSL文件,将其转换为html(xunit.xsl):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<h2>Tests Results</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>TestClass</th>
<th>TestName</th>
<th>TestResult</th>
<th>Message</th>
</tr>
<xsl:for-each select="testsuite/testcase">
<tr>
<xsl:choose>
<xsl:when test="@classname">
<td>
<xsl:value-of select="@classname" />
</td>
</xsl:when>
<xsl:otherwise>
<td>No Class</td>
</xsl:otherwise>
</xsl:choose>
<td>
<xsl:value-of select="@name" />
</td>
<xsl:choose>
<xsl:when test="failure">
<td>FAIL</td>
</xsl:when>
<xsl:otherwise>
<td>SUCCESS</td>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="failure">
<td><xsl:value-of select="failure/@message" /></td>
</xsl:when>
<xsl:otherwise>
<td>SUCCESS</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我的xUnit命令如下所示:
xunit (testTimeMargin: '3000',
thresholdMode: 1,
thresholds: [],
tools: [Custom(customXSL: 'xunit.xsl', deleteOutputFiles: true, failIfNotNew: true, pattern: 'outputs/xunit.xml', skipNoTestFiles: false, stopProcessingIfError: true)]
)
我收到以下错误:
ERROR: cvc-elt.1: Cannot find the declaration of element 'html'.
ERROR: The plugin hasn't been performed correctly: The converted file for the result file '/home/centos/jenkins/workspace/scheduler/outputs/xunit.xml' (during conversion process for the metric 'Custom Tool') is not valid. The report file has been skipped.