使用 cucumber-jvm 4 并行运行黄瓜测试 [英] run cucumber tests parallel using cucumber-jvm 4

查看:23
本文介绍了使用 cucumber-jvm 4 并行运行黄瓜测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java v8.x - spring 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 have two questions making me confuse.

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

感谢任何帮助.

推荐答案

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

Parallel support was introduced in cucumber-jvm:4.0.0. So your dependencies are ok.

如果您使用的是 Maven:

If you are using Maven:

Cucumber JUnit - 使用 Maven 并行执行

Cucumber JUnit 支持跨多个线程并行执行功能文件.要使用 maven 启用此功能,请将并行属性设置为 methodsboth.

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.

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.

Gradle Cucumber runner - 并行运行功能

如果你指定数量,Cucumber 支持并行执行要使用的线程.这可以通过两种方式完成

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

  • 从命令行运行的选项,./gradlew cucumber --threads 4,这将运行四个并行线程
  • 一个扩展,即在你的 build.gradle 文件中的 cucumber 部分设置值.
  • 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 
}

这将使用尽可能多的线程,同时将资源留给要执行的 Gradle.

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

这篇关于使用 cucumber-jvm 4 并行运行黄瓜测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆