1

使用 TestNg 并行运行测试时,报告、可发送电子邮件和 testng-results.xml 似乎被覆盖并仅显示来自最后一个线程的结果,而不是所有线程的组合。

示例 testng.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 和 testng-results xml 仅显示来自测试名称“2”的测试方法的结果,即使 testng-results.xml 能够读取所有测试名称。

示例 testng-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 种方法的结果。

4

1 回答 1

1

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

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

并使用简单的命令行实用程序prettyjunit将 junit xml 报告转换为摘要 html 。

于 2021-06-22T20:24:52.967 回答