【问题标题】:What XSLT converts JUnit Xml format to JUnit Plain format什么 XSLT 将 JUnit Xml 格式转换为 JUnit Plain 格式
【发布时间】:2012-02-27 18:18:10
【问题描述】:

我正在将我的构建从 Ant 转移到 Gradle。 Ant 允许 JUnit 任务创建多个不同格式的报告。 Gradle 更具限制性——它生成一个 HTML 报告和一个 XML 报告。 XML 报告是 JUnit 文本报告的超集,因此它可以从一个转换到另一个。什么 XSLT 将 XML 转换为文本?这是一个示例 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>

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

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

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

【问题讨论】:

  • 那么,问题是什么?我没有看到。
  • @DimitreNovaatchev,感谢您指出我的遗漏。我从这里开始回答这个问题:stackoverflow.com/questions/3671613/…。如果这确实是一个不恰当的问题,我很乐意撤回它。我认为它可能具有一般用途,因为它与从一个构建系统迁移到另一个构建系统有关。
  • Spina,这并没有什么不妥——只是好像你希望有人为你做全部工作——并不是你自己尝试过,写了一个转换并且有问题。这里的人愿意帮助做这项工作,而不是做全部工作。更重要的是你学到了一些东西。当人们为您完成所有工作时,您学习/理解的机会就很小。

标签: xml xslt junit report


【解决方案1】:

给你。

<?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>

不过,您可能想尝试一下格式化。

【讨论】:

猜你喜欢
  • 2017-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-30
  • 1970-01-01
  • 2011-06-22
  • 1970-01-01
相关资源
最近更新 更多