[英]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.