Issue
I am trying to setup serenity cucumber tests to run in parallel
I have added all the necessary configuration that have been mentioned but for some reason tests are executed in a single thread. I tried various combinations with forkCount, threadCount, parallel, useUnlimitedThreadCounts etc nothing seems to work.
Also tried having a dependency for JUnit 4 and 5 which didnt work as well.
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<properties>
<serenity.version>2.2.5</serenity.version>
<serenity.maven.version>2.2.5</serenity.maven.version>
<serenity.cucumber5.version>2.2.2</serenity.cucumber5.version>
<cucumber.version>5.6.0</cucumber.version>
<selenium.version>3.141.59</selenium.version>
</properties>
<dependencies>
<!-- Cucumber -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<!-- Serenity -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
<exclusions>
<exclusion>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-cucumber5</artifactId>
<version>${serenity.cucumber5.version}</version>
</dependency>
<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M4</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M4</version>
</dependency>
</dependencies>
<configuration>
<parallel>classes</parallel>
<threadCount>2</threadCount>
<forkCount>2C</forkCount>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The maven debug logs for verify indicates parallelMavenExecution is set to false for some reason.
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M4:integration-test from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M4, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@4f8e5cde]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M4:integration-test' with basic configurator -->
[DEBUG] (s) additionalClasspathElements = []
[DEBUG] (s) basedir = /Users/vinothraj/IdeaProjects/hiscox-usa-portal-testsuite
[DEBUG] (s) childDelegation = false
[DEBUG] (s) classpathDependencyExcludes = []
[DEBUG] (s) defaultClassesDirectory = /target/classes
[DEBUG] (s) dependenciesToScan = []
[DEBUG] (s) disableXmlReport = false
[DEBUG] (s) enableAssertions = true
[DEBUG] (f) excludedEnvironmentVariables = []
[DEBUG] (f) forkCount = 2C
[DEBUG] (s) forkMode = once
[DEBUG] (s) forkedProcessExitTimeoutInSeconds = 30
[DEBUG] (s) junitArtifactName = junit:junit
[DEBUG] (s) localRepository = id: local
url: file:///.m2/repository/
layout: default
snapshots: [enabled => true, update => always]
releases: [enabled => true, update => always]
[DEBUG] (s) parallel = classes
[DEBUG] (f) parallelMavenExecution = false
[DEBUG] (s) parallelOptimized = true
[DEBUG] (s) perCoreThreadCount = true
Thanks in advance.
Solution
You're using the wrong value for parallel
. You have to set it to methods or both. Otherwise Surefire will run all tests of your runner class serially.
https://github.com/cucumber/cucumber-jvm/tree/main/cucumber-junit
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>
<!-- Use 2.22.1 or higher -->
<version>${maven-surefire-plugin.version}</version>
<configuration>
<parallel>both</parallel>
<threadCount>4</threadCount>
</configuration>
</plugin>
</plugins>
</build>
Answered By - M.P. Korstanje
Answer Checked By - David Goodson (JavaFixing Volunteer)