简体   繁体   English

仅当测试失败时,如何使Ant junit任务显示详细信息?

[英]How to make Ant junit task show detail only if a test fails?

My Ant junit task is currently set to output minimal information. 我的Ant junit任务当前设置为输出最少的信息。 On the console, for each test class, it prints the class name, how many tests were run, failed, and errored, along with the elapsed time for each test. 在控制台上,对于每个测试类,它会打印类名称,运行,失败和错误的测试数量以及每个测试的经过时间。 If the test failed, there's an additional line saying the test failed. 如果测试失败,则还有另外一行表示测试失败。

I'd like to get additional detail on the console, but ONLY if a test fails. 我想在控制台上获得更多详细信息,但是仅在测试失败的情况下。 If I follow advice like this , by adding an additional plain formatter with usefile=false, then I get additional redundant detail for ALL tests, even if all tests pass. 如果我按照建议像这样 ,通过添加具有usefile额外的普通格式化=假,然后我得到了所有测试的额外多余的细节,即使通过了所有测试。 This includes printing each test method executed, and a redundant line for each test class. 这包括打印执行的每个测试方法,以及每个测试类的冗余行。

Is it possible to get this? 有可能得到这个吗?

I believe I've implemented a reasonable solution. 我相信我已经实施了合理的解决方案。

The key points of the solution are: * Executing a task after the unit tests are complete, which only runs if "test.failed" * Use the "xmltask" task library to parse the test results files and emit concise results 解决方案的关键点是:*在单元测试完成后执行任务,仅在“ test.failed”下运行; *使用“ xmltask”任务库来解析测试结果文件并发出简洁的结果

I wrote the following target to do this: 为此,我编写了以下目标:

<target name="show-unit-test-failures" if="test.failed">
    <taskdef if:set="xmltask.present" name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
    <echo if:set="xmltask.present" message="Unit test failure report details:"/>
    <xmltask if:set="xmltask.present">
        <fileset dir="gen/reports/artifacts/junit">
            <include name="TEST-*Test.xml"/>
        </fileset>
        <call path="//testcase[./error]">
            <parThatam name="className" path="@classname"/>
            <param name="methodName" path="@name"/>
            <param name="errorText" path="./error/text()"/>
            <actions>
                <echo>---------------------------------</echo>
                <echo>@{className}.@{methodName}:</echo>
                <echo>@{errorText}</echo>
            </actions>
        </call>
        <call path="//testcase[./failure]">
            <param name="className" path="@classname"/>
            <param name="methodName" path="@name"/>
            <param name="errorText" path="./failure/text()"/>
            <actions>
                <echo>---------------------------------</echo>
                <echo>@{className}.@{methodName}:</echo>
                <echo>@{errorText}</echo>
            </actions>
        </call>
    </xmltask>
</target>

Note that I also let it "fail gracefully" if the "xmltask.jar" file isn't available. 请注意,如果“ xmltask.jar”文件不可用,我也会让它“正常失败”。 The ability to reference namespaces in tasks is a new feature in Ant 1.9.1 and newer. 在任务中引用名称空间的功能是Ant 1.9.1和更高版本中的一项新功能。

I call this target at the end of my "run-unit-test" target. 我将这个目标称为“运行单元测试”目标的结尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM