testng-results.xml文件在并行运行测试时被覆盖



当使用TestNg并行运行测试时,报告、emailable和TestNg -results.xml似乎被覆盖,只显示最后一个线程的结果,而不是所有线程的组合。

test .xml文件示例

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Smoke Suite" parallel="tests" thread-count="2">
<groups>
<run>
<include name="Smoke"/>
</run>
</groups>
<test name="1">
<classes>
<class name="one">
<parameter name="executionId" value="UIXTC-"/>
</class>
</classes>
</test>
<test name="2">
<classes>
<class name="two">
<parameter name="executionId" value="UIXTC-"/>
</class>
</classes>
</test>
</suite>

成功的细节
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/com/blueoptima/${MODULE}/suiteXmls/${SUITE}Suite.xml</suiteXmlFile>
</suiteXmlFiles>
<threadCount>${THREADS}</threadCount>
<environmentVariables>
<PROPERTIES_FILE>${PROPERTIES_FILE}</PROPERTIES_FILE>
</environmentVariables>
</configuration>
</plugin>

emailable和testing -results xml显示了测试名称"2"中测试方法的结果。虽然testing -results.xml能够读取所有的测试名称,但只能读取。

示例test -results.xml输出文件

<?xml version="1.0" encoding="UTF-8"?>
<testng-results ignored="21" total="22" passed="1" failed="0" skipped="0">
<reporter-output>
</reporter-output>
<suite started-at="2021-01-28T18:06:49 IST" name="Smoke Suite" finished-at="2021-01-28T18:10:40 IST" 
duration-ms="230568">
<groups>
<group name="sanity">
<method signature="method 2" name="method 2" class="Class 2"/>
<method signature="method 3" name="method 3" class="Class 3"/>
</group> <!-- sanity -->
<group name="Smoke">
<method signature="method 1" name="method 1" class="Class 1"/>
<method signature="method 2" name="method 2" class="Class 2"/>
<method signature="method 3" name="method 3" class="Class 3"/>
</group> <!-- Smoke -->
</groups>
<test-method signature="method 1" started-at="2021-01-28T18:09:24 IST" name="method 1" data- 
provider="dataProviderForTest" finished-at="2021-01-28T18:10:32 IST" duration-ms="67731" 
status="PASS">
<params>
<param index="0">
<value>
<![CDATA[{testCaseId=UIXTC-}]]>
</value>
</param>
</params>
<reporter-output>
</reporter-output>
</test-method>

可以看到,它能够识别烟雾套件中的所有3种方法,但只显示了1种方法的结果。

作为此问题的解决方案,您可以在测试xml中添加junit侦听器(捕获所有线程),如下所示

<suite name = "Sample Tests">
<listeners>
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
</listeners>

,并使用简单的命令行实用程序prettyjunit将junit XML报告转换为汇总的HTML。

最新更新