gpt4 book ai didi

cucumber - 使用 cucumber-jvm 4 并行运行 cucumber 测试

转载 作者:行者123 更新时间:2023-12-03 23:31:19 24 4
gpt4 key购买 nike

Java v8.x - spring v5.x cucumber v4.2.0

我试过 temyers/cucumber-jvm-parallel-plugin 并且工作正常,但是当我进入他们的 gitihub 页面时,他们宣布停止使用这个插件 b/c cucumber 已经开始支持并行测试来自 cucumber-jvm 4.0.0 的运行支持。

我有使用以下 maven 依赖项的现有测试。

cucumber-java v4.2.0
cucumber-junit v4.2.0
cucumber-spring v4.2.0

我有两个问题让我很困惑。

  1. 为了使用 cucumber-jvm,我必须更改我的依赖项,否则我当前的依赖项将起作用。
  2. 我可以只传递一个参数 --parallel 来启动并行 cucumber 测试吗?

感谢任何帮助。

最佳答案

cucumber-jvm:4.0.0 中引入了并行支持。所以你的依赖没问题。

如果您使用的是 Maven:

Cucumber JUnit - Parallel Execution with Maven

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>

如果您使用的是 Gradle,最好使用 Gradle Cucumber 插件,因为 Gradle 不支持子类级别的并行化。在这种情况下,您不需要 cucumber-junit

Gradle Cucumber runner - Running features in parallel

Cucumber supports parallel execution if you specify the number of thread to use. This can be done in two ways

  • 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.

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
}

This will use as many threads as possible while leaving resources for Gradle to execute.

关于cucumber - 使用 cucumber-jvm 4 并行运行 cucumber 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55304142/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com