简体   繁体   English

使用 Cucumber 在 Spring 中指定不与 TestNG 运行器并行运行的测试用例

[英]Specify test case not to run in parallel with TestNG runner in Spring using Cucumber

I've been able to configure the project to run test cases in parallel using a TestNG runner;我已经能够将项目配置为使用 TestNG 运行器并行运行测试用例; however, there are a handful of scenarios that are not very thread safe.但是,有一些场景不是线程安全的。 If these test cases were to run in parallel, they'd interfere with each other.如果这些测试用例要并行运行,它们会相互干扰。 Now there are a couple of ways I could make these scenarios thread safe, but I was wondering if there was a way to specify these Cucumber scenarios not to run in parallel.现在有几种方法可以使这些场景线程安全,但我想知道是否有办法指定这些 Cucumber 场景不并行运行。

Is there a specific tag I could configure to tag scenarios not to run in parallel?我可以配置一个特定的标签来标记不并行运行的场景吗? Specify certain feature files not to run in parallel?指定某些功能文件不并行运行? I believe I might have come across something like that for JUnit 5, but does this exist with TestNG?我相信我可能会遇到类似 JUnit 5 的情况,但是 TestNG 是否存在这种情况?

Unlike JUnit 5, TestNG does not provide such fine-grained controls.与 JUnit 5 不同,TestNG 不提供这种细粒度的控件。 At best you can create multiple runner classes with a different selection of features and different configurations for parallel/serial execution.充其量您可以创建多个具有不同功能选择和不同配置的运行器类,用于并行/串行执行。

Another thing I just realized was I could make the number of threads an argument;我刚刚意识到的另一件事是我可以将线程数作为参数。 with a default of 1 thread.默认为 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>

I have one Jenkins build that has all the tests tagged with the same name to run in parallel with however many threads needed.我有一个 Jenkins 版本,其中所有测试都标记有相同的名称,可以与需要的线程并行运行。

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

And in the other build, I have a very similar command (with a different tag) just without the added arguement;在另一个版本中,我有一个非常相似的命令(带有不同的标签),只是没有添加争论; to use the default of just one thread.仅使用一个线程的默认值。 This will run all those tagged tests one at a time.这将一次运行所有这些标记的测试。

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

Either way, the first answer still works, but just thought to add this possibility.无论哪种方式,第一个答案仍然有效,但只是想增加这种可能性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 TestNG 测试运行器运行单个 Cucumber 场景 - Can't run individual Cucumber scenarios using TestNG test runner 无法使用 TestNG 和 SpringBootTest 并行运行 Cucumber 测试 - Cant run Cucumber tests in parallel using TestNG and SpringBootTest 使用testNG并行运行测试 - Make test run in parallel using testNG 如何在多个并行线程中运行单个 testng 测试用例 - How to run a single testng test case in multiple parallel threads 无法在Cucumber&Testng中运行并行测试 - Unable to run parallel tests in Cucumber &Testng 黄瓜testng赛跑者失败 - Cucumber testng runner fails org.testng.TestNGException:无法实例化黄瓜测试运行器 - org.testng.TestNGException: Cannot instantiate cucumber test runner 如何使用testng并行运行我的硒测试方法 - how to run my selenium test methods in parallel using testng 如何使用TestNG并行运行属于特定组的测试用例 - How to run test cases belonging to a particular group in parallel using TestNG 如何在各自的测试文件夹中为每个测试生成 cucumber.json(我使用的是 Cucumber 5,它使用 Z0F10ECB7756532AE8DAE8CA448 进行并行执行) - How to generate cucumber.json per test in respective test folders (I am using Cucumber 5 which uses TestNG for parallel execution)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM