使用黄瓜-jvm 4并行运行黄瓜测试 [英] run cucumber tests parallel using cucumber-jvm 4
问题描述
Java v8.x-春季v5.x黄瓜v4.2.0
Java v8.x - spring v5.x cucumber v4.2.0
我尝试了 temyers / cucumber-jvm-parallel-plugin
并能正常工作,但是当我进入他们的gitihub页面时,他们宣布停止使用此插件。b / c黄瓜已经开始支持cucumber-jvm 4.0.0的并行测试运行支持。
i tried temyers/cucumber-jvm-parallel-plugin
and it works fine, but when i get to their gitihub page they announced to stop using this plugin b/c cucumber already have start supporting parallel test running support from cucumber-jvm 4.0.0.
我已经使用以下maven依赖项进行了现有测试。
I have existing tests with using following maven dependencies.
cucumber-java v4.2.0
cucumber-junit v4.2.0
cucumber-spring v4.2.0
i有两个问题让我感到困惑。
i have two questions making me confuse.
- 为了使用cumulage-jvm,我必须更改依赖项,否则当前的依赖项将起作用。
- 我可以通过传递参数--parallel来开始并行黄瓜测试吗?
任何帮助
推荐答案
在 cucumber-jvm:4.0.0 $ c中引入了并行支持。 $ c>。因此,您的依赖关系就可以了。
Parallel support was introduced in cucumber-jvm:4.0.0
. So your dependencies are ok.
如果您使用的是Maven:
If you are using Maven:
< a href = https://github.com/cucumber/cucumber-jvm/tree/v4.0.0/junit rel = noreferrer>黄瓜JUnit-使用Maven并行执行
黄瓜JUnit支持跨多个线程并行执行功能文件。要使用maven启用此功能,请将parallel属性设置为方法
或两者
。
Cucumber JUnit supports parallel execution of feature files across multiple threads. To enable this with maven set the parallel property to either methods
or both
.
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<parallel>both</parallel>
<threadCount>4</threadCount>
</configuration>
</plugin>
</plugins>
</build>
如果您使用的是Gralde,最好使用Gradle Cucumber Plugin as Gradle不支持子类级别的并行化。在这种情况下,您不需要黄瓜junit
。
If you are using Gralde you are better off using the Gradle Cucumber Plugin as Gradle doesn't support sub-class level parallelization. In this case you don't need cucumber-junit
.
如果您指定要使用的
线程数,则黄瓜支持并行执行。这可以通过两种方式完成:
Cucumber supports parallel execution if you specify the number of thread to use. This can be done in two ways
- 从命令行运行的一个选项
。线程4
,它将运行四个并行线程 - 扩展,即在您的
build.gradle $ c中设置值$ c>黄瓜部分中的文件。
- An option whn running from a command line,
./gradlew cucumber --threads 4
, this will run four parallel threads - An extension, that is setting the value in your
build.gradle
file in the cucumber section.
在构建脚本中设置值时,您真的不知道$ b如何$ b构建将有权访问的许多线程。硬编码固定数字
可能不是您的最佳选择。
When setting the value in the build script, you can't really know how many threads the build will have access to. Hardcoding a fixed number may not be your best option.
指定要使用的线程数的一种方法是:
One way of specifying the number of threads to use is:
cucumber {
threads = = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}
这将使用尽可能多的线程,同时保留资源供
Gradle执行。
This will use as many threads as possible while leaving resources for Gradle to execute.
这篇关于使用黄瓜-jvm 4并行运行黄瓜测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!