3
votes

Java v8.x - spring v5.x cucumber v4.2.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.

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. In order to use cucumber-jvm do i have to change my dependencies or my current dependencies will work.
  2. can i start parallel cucumber tests just passing a parameter --parallel ?

any help is appreciated.

1

1 Answers

8
votes

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

If you are using 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>

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