gpt4 book ai didi

unit-testing - 如何将自定义XSL模板应用于Android Studio JUnit测试运行?

转载 作者:行者123 更新时间:2023-12-03 17:55:07 25 4
gpt4 key购买 nike

如果我在Android Studio中运行一组单元测试(也将在IntelliJ IDEA中应用),则可以使用此对话框导出测试结果:

export test results dialog

如果选择“导出格式/ HTML”,则将得到一个如下所示的文件:

test report html

一切都很好。但是,我有一个要求,我必须在带有模板的Word文件中显示测试报告。如果我在浏览器中复制/粘贴默认HTML,看来HTML太复杂,Word无法正确处理,而且看起来也不好。

result of copying into Word

我需要测试报告的某种纯文本表示形式,可以将其复制到Word / Excel中并作为报告的一部分包含在内。

从上面的对话框中可以看出,选项之一是应用XSL模板来生成结果。我想编写一个XSL模板,以将JUnit单元测试报告呈现为简单的东西,使我可以轻松地复制/粘贴。请注意,默认情况下,Android Studio或IntelliJ IDEA没有提供XSL模板。

如果我为缩小的JUnit测试报告导出XML,则它看起来像这样:

<?xml version="1.0" encoding="UTF-8"?><testrun duration="1" footerText="Generated by Android Studio on 4/05/17 12:43 PM" name="myapplication in app">
<count name="total" value="3"/>
<count name="passed" value="3"/>
<config nameIsGenerated="true" configId="AndroidJUnit" name="myapplication in app">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea"/>
<module name="app"/>
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false"/>
<option name="ALTERNATIVE_JRE_PATH"/>
<option name="PACKAGE_NAME"/>
<option name="MAIN_CLASS_NAME"/>
<option name="METHOD_NAME"/>
<option name="TEST_OBJECT" value="directory"/>
<option name="VM_PARAMETERS"/>
<option name="PARAMETERS"/>
<option name="WORKING_DIRECTORY"/>
<option name="ENV_VARIABLES"/>
<option name="PASS_PARENT_ENVS" value="true"/>
<option name="TEST_SEARCH_SCOPE">
<value defaultName="singleModule"/>
</option>
<envs/>
<dir value="/Users/example/AndroidStudioProjects/MyApplication5/app/src/test/java/com/example/myapplication"/>
<patterns/>
</config>
<root name="&lt;default package&gt;" location="java:suite://&lt;default package&gt;"/>
<suite duration="1" locationUrl="java:suite://com.example.myapplication.ArithmeticTest" name="ArithmeticTest" status="passed">
<test duration="1" locationUrl="java:test://com.example.myapplication.ArithmeticTest.multiplication_isCorrect" name="ArithmeticTest.multiplication_isCorrect" status="passed"/>
<test duration="0" locationUrl="java:test://com.example.myapplication.ArithmeticTest.addition_isCorrect" name="ArithmeticTest.addition_isCorrect" status="passed"/>
</suite>
<suite duration="0" locationUrl="java:suite://com.example.myapplication.StringTest" name="StringTest" status="passed">
<test duration="0" locationUrl="java:test://com.example.myapplication.StringTest.concatenation_isCorrect" name="StringTest.concatenation_isCorrect" status="passed"/>
</suite>
</testrun>


题:
我可以应用什么XSL模板来将XML转换成非常普通的HTML,然后可以将其复制/粘贴到公司的Word文件中?

注意:以自我回答的形式提出,但其他回答也很受欢迎,如果质量良好,我们会接受

最佳答案

考虑到时间限制和缺乏XSL知识,这是我的最佳尝试。

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1" style="width:100%">
<th>TestRun</th>
<th>Total</th>
<th>Passed</th>
<tr>
<td>
<xsl:value-of select="concat(testrun/@name, ' - ', testrun/@footerText)"/>
</td>
<td>
<xsl:value-of select="testrun/count[1]/@value"/>
</td>
<td>
<xsl:value-of select="testrun/count[2]/@value"/>
</td>
</tr>
</table>
<xsl:for-each select="testrun/suite">
<table border="1" style="width:100%">
<th>
<xsl:value-of select="@name"/>
</th>
<th></th>
<th></th>
<xsl:for-each select="test">
<tr>
<td>
<xsl:value-of select="@name"/>
</td>
<td>
<xsl:value-of select="@duration"/>ms</td>
<td>
<xsl:value-of select="@status"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


根据需要,它会生成一个非常基本的HTML,可以将其复制并粘贴到Office中。

关于unit-testing - 如何将自定义XSL模板应用于Android Studio JUnit测试运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43772160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com