【问题标题】:testng-results.xml file getting overridden when running tests in parallel并行运行测试时,testng-results.xml 文件被覆盖
【发布时间】:2021-05-02 10:04:20
【问题描述】:

使用 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 种方法的结果。

【问题讨论】:

    标签: selenium-webdriver testng testng.xml


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2016-01-27
      • 1970-01-01
      • 1970-01-01
      • 2021-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-04
      • 2019-02-01
      相关资源
      最近更新 更多