Skip to content

Parallel Test Execution

alvarolaserna edited this page Oct 15, 2019 · 2 revisions

FORKING FOR PARALLELISATION

There are two ways to accomplish this task. The following one is by using multiple java runners, that will be forked by maven surefire plugin or failsafe plugin. This is method is easier to implement since static variables wont be share between forks, and if you choose to use multi-threading, you might struggle with this. In any case, the framework supports multithreading, and you can use this alternative (check cucumber built-in parallel execution).

Then what you should do is first to set your pom with this two configuration options:

        <forkCount>2</forkCount>  
        <reuseForks>true</reuseForks>

The reuseForks is optional but highly recommended to reduce execution time. The forkCount you will change it for the number of parallel forks you want to execute at the same time.

Now you can write 2 runners with different tests, or in case you use cucumber 2 runners with different tags or pointing to different feature files.

The reason why we are not using the cucumber build in parallel implementation is because it uses multi-threading, and that will most likely break your tests (as aforementioned). While it's true that forking requires more resources than threading, this is shouldn't be a big problem for normal projects.

We are currently working on a "Thread-Safe" version for those who need multi-thread execution.

Note: You can also use the following alternatives for cucumber:

  1. Using cucumber-jvm-parallel-plugin. This plugin generates test runners for each feature or scenario. You can modify the options for parallel execution in the pom.xml, but first you have to delete the plugins in the file and add the ones in pom_cucumber_parallel.txt. More info about this plugin Here
  2. Using Cucable plugin developed by Trivago. It works similar to the cucumber plugin aforementioned. To use it delete the plugins in the pom.xml and add the ones in pom_cucable.txt. More info about this plugin Here

FULL PLUGINS POM EXAMPLE:

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${maven.failsafe.plugin.version}</version>
                <executions>
                    <execution>
                        <id>Run parallel tests</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <forkCount>${cucumber.forks}</forkCount>
                    <reuseForks>true</reuseForks>
                    <testFailureIgnore>true</testFailureIgnore>
                    <systemPropertyVariables>
                        <allure.results.directory>target/allure-results</allure.results.directory>
                        <allure.link.issue.pattern>https://example.com/{}</allure.link.issue.pattern>
                        <allure.link.tms.pattern>https://example.com/{}</allure.link.tms.pattern>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.plugin.version}</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>

Clone this wiki locally