【问题标题】:Specify test case not to run in parallel with TestNG runner in Spring using Cucumber使用 Cucumber 在 Spring 中指定不与 TestNG 运行器并行运行的测试用例
【发布时间】:2022-08-11 02:56:12
【问题描述】:

我已经能够将项目配置为使用 TestNG 运行器并行运行测试用例;但是,有一些场景不是线程安全的。如果这些测试用例要并行运行,它们会相互干扰。现在有几种方法可以使这些场景线程安全,但我想知道是否有一种方法可以指定这些 Cucumber 场景不并行运行。

我可以配置一个特定的标签来标记不并行运行的场景吗?指定某些功能文件不并行运行?我相信我可能在 JUnit 5 中遇到过类似的情况,但是 TestNG 是否存在这种情况?

    标签: java spring automation cucumber testng


    【解决方案1】:

    与 JUnit 5 不同,TestNG 不提供这种细粒度的控件。充其量您可以创建多个运行器类,它们具有不同的功能选择和不同的并行/串行执行配置。

    【讨论】:

    • 是的,实际上我没想过要有多个跑步者。好主意。这样我就可以标记我想自己运行的任何测试,并在他们自己的运行器中指定它们。再次感谢。
    【解决方案2】:

    我刚刚意识到的另一件事是我可以将线程数作为参数。默认为 1 个线程。

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven.surefire.version}</version>
        <configuration>
            <testFailureIgnore>true</testFailureIgnore>
                        <properties>
                            <property>
                                <name>dataproviderthreadcount</name>
                                <value>1</value>
                            </property>
                        </properties>
                        <includes>
                            <include>api.automation.tests.runners.TestNGRunnerTest</include>
                        </includes>
        </configuration>
    </plugin>
    

    我有一个 Jenkins 构建,其中所有测试都标记有相同的名称,可以与需要的线程并行运行。

    mvn clean test -Dcucumber.filter.tags="${CucumberFilterTag} and not @opentofix" -Dspring.profiles.active=${Environment} -Ddataproviderthreadcount=4
    

    在另一个版本中,我有一个非常相似的命令(带有不同的标签),只是没有添加争论;仅使用一个线程的默认值。这将一次运行所有这些标记的测试。

    mvn clean test -Dcucumber.filter.tags="${CucumberFilterTag} and not @opentofix" -Dspring.profiles.active=${Environment}
    

    无论哪种方式,第一个答案仍然有效,但只是想增加这种可能性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-09
      • 2021-02-20
      • 1970-01-01
      • 2018-03-24
      • 2015-08-14
      • 2018-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多