【问题标题】:TestNG is not running 10 threads in parallelTestNG 没有并行运行 10 个线程
【发布时间】:2021-04-30 02:19:30
【问题描述】:

我正在使用 Maven 和 Testng 来运行我的 java-Tests。我有一个 java 类,我有 10 个测试。但由于某种原因,只有 5 个测试随机开始。有时可能是 1-3-7-8-10,有时可能是 1-2-4-7-9 等等。

我需要并行运行它们,每个线程中的每个测试全部十个测试。

我尝试使用"thread-count="10"thread-count="10" data-provider-thread-count="3",但无济于事。所以我决定看一下 pom.xml。所以下面的设置是我当前的最新配置。 testng.xml:

<suite name="AllTestsSuite" parallel="methods" allow-return-values="true">
    <listeners>
        <listener class-name="basicCommands.WebDriverListener">    
        </listener>
    </listeners>    
    <test name="name">
        <classes>
            <class name="name-to-class"/>
        </classes>
    </test>
</suite>

maven pom.xml。我正在使用 maven-surefire-plugin,所以在这个插件的设置中我有:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
                    <systemPropertyVariables>
                          ...                           
                    </systemPropertyVariables>
                    <suiteXmlFiles>
                         ...    
                    </suiteXmlFiles>
                    <properties>
                        <property>
                            <name>parallel</name>
                            <value>methods</value>
                        </property>
                        <property>
                            <name>threadcount</name>
                            <value>10</value>
                        </property>
                        <property>
                            <name>dataproviderthreadcount</name>
                            <value>5</value>
                        </property>
                    </properties>
                </configuration>

            </plugin>

我的设置出了什么问题,我可以从一个班级同时开始 10 个测试吗? 谢谢。

【问题讨论】:

  • 例如,您没有thread-count,您是否还检查了是否有其他东西限制了我们在testng之外的线程?
  • 但我在 pom.xml 中有它。无论如何,即使我在 testng.xml 中添加了 thread-count = "10",也只有 5 个线程正在启​​动。 >您是否还检查了是否有其他东西限制了我们在 testng 本身之外的线程?如何以及在哪里?你能建议我在哪里检查吗?
  • 可能与使用WebDriver有关,见stackoverflow.com/questions/37304962/…
  • 我会看看,但我不确定.. 在 Jenkins 我看到十行 10:54:56 Jan 26, 2021 10:54:56 AM org.openqa.selenium.remote .ProtocolHandshake createSession,看起来 Selenium 创建了 10 个会话,但根本不会启动 10 个测试来运行。

标签: java multithreading maven testng


【解决方案1】:

看在上帝的份上,我怎么能这么不体贴,错过那该死的台词。

private ExecutorService executorService = Executors.newFixedThreadPool(5);

问题解决

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多