什么 XSLT 将 JUnit Xml 格式转换为 JUnit 纯格式 [英] What XSLT converts JUnit Xml format to JUnit Plain format

查看:23
本文介绍了什么 XSLT 将 JUnit Xml 格式转换为 JUnit 纯格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的构建从 Ant 迁移到 Gradle.Ant 允许 JUnit 任务创建具有不同格式的多个报告.Gradle 的限制性更强——它生成一个 HTML 报告和一个 XML 报告.XML 报告是 JUnit 文本报告的超集,因此可以从一种转换到另一种.什么 XSLT 会将 XML 转换为文本?这是一个示例 XML:

I'm moving my build from Ant to Gradle. Ant allows multiple reports with different formats to be created by the JUnit task. Gradle is more restrictive-- it generates a HTML report and a XML report. The XML report is a superset of the JUnit text report so it can be transformed from one to the other. What XSLT will convert the XML to the Text? Here is an example XML:

<?xml version="1.0" encoding="UTF-8"?>
<testsuite errors="0" failures="0" hostname="spina.stsci.edu" name="edu.stsci.CoSI.test.DependencySupressingConstraintJUnitTest" tests="6" time="0.14" timestamp="2012-02-27T18:08:03">
  <properties />
  <testcase classname="edu.stsci.CoSI.test.DependencySupressingConstraintJUnitTest" name="testSupressionWorks" time="0.01" />
  <testcase classname="edu.stsci.CoSI.test.DependencySupressingConstraintJUnitTest" name="testSupressionWorksWithDependenciesDisabled" time="0.0020" />
  <testcase classname="edu.stsci.CoSI.test.DependencySupressingConstraintJUnitTest" name="testPropagationIsDeferred" time="0.0010" />
  <testcase classname="edu.stsci.CoSI.test.DependencySupressingConstraintJUnitTest" name="testPropagationIsDeferredWhenDependenciesAreSuppressed" time="0.0010" />
  <testcase classname="edu.stsci.CoSI.test.DependencySupressingConstraintJUnitTest" name="testPropagationIsDeferredWhenDependenciesAreSuppressed2" time="0.0010" />
  <testcase classname="edu.stsci.CoSI.test.DependencySupressingConstraintJUnitTest" name="testGarbageCollection" time="0.066" />
  <system-out><![CDATA[Running Supressing Constraint
    Running Supressing Constraint
    Running Supressing Constraint
    Change Me is: 2
    Running Supressing Constraint
    Change Me is: 5
    ]]></system-out>
  <system-err><![CDATA[]]></system-err>
</testsuite>

这是我希望它生成的文本:

Here is the text that I would like it to produce:

Testsuite: edu.stsci.CoSI.test.DependencySupressingConstraintJUnitTest
Tests run: 6, Failures: 0, Errors: 0, Time elapsed: 0.363 sec
------------- Standard Output ---------------
Running Supressing Constraint
Running Supressing Constraint
Running Supressing Constraint
Change Me is: 2
Running Supressing Constraint
Change Me is: 5
------------- ---------------- ---------------

Testcase: testSupressionWorks took 0.001 sec
Testcase: testSupressionWorksWithDependenciesDisabled took 0.001 sec
Testcase: testPropagationIsDeferred took 0 sec
Testcase: testPropagationIsDeferredWhenDependenciesAreSuppressed took 0.001 sec
Testcase: testPropagationIsDeferredWhenDependenciesAreSuppressed2 took 0 sec
Testcase: testGarbageCollection took 0.038 sec

某些细节并不重要(例如秒的格式).

Certain details aren't important (like the format of the seconds).

推荐答案

给你.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" indent="no"/>

  <xsl:template match="/testsuite">
    Testsuite: <xsl:value-of select="@name" />
    <xsl:text>
    Tests run: </xsl:text>
    <xsl:value-of select="@tests" />
    <xsl:text>, Failures: </xsl:text>
    <xsl:value-of select="@failures" />
    <xsl:text>, Errors: </xsl:text>
    <xsl:value-of select="@errors" />
    <xsl:text>, Time elapsed: </xsl:text>
    <xsl:value-of select="@time" />
    <xsl:text> sec</xsl:text>
    <xsl:apply-templates select="system-out" />
    <xsl:apply-templates select="system-err" />
    <xsl:text>
    --------- ----------- ---------
    </xsl:text>
    <xsl:apply-templates select="testcase" />
  </xsl:template>

  <xsl:template match="testcase">
    <xsl:text>
    Testcase: </xsl:text>
    <xsl:value-of select="@name" />
    <xsl:text> took </xsl:text>
    <xsl:value-of select="@time" />
  </xsl:template>

  <xsl:template match="system-out">
    <xsl:text>
    ------ Standard output ------
    </xsl:text>
    <xsl:value-of select="." />
  </xsl:template>

  <xsl:template match="system-err">
    <xsl:text>
    ------ Error output ------
    </xsl:text>
    <xsl:value-of select="." />
  </xsl:template>

</xsl:stylesheet>

不过,您可能想稍微调整一下格式.

You probably want to play a bit with the formatting though.

这篇关于什么 XSLT 将 JUnit Xml 格式转换为 JUnit 纯格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆