Cucumber Parallel Execution JUnit

Profile picture for user devraj

Cucumber can be executed in parallel using JUnit and Maven test execution plugins. You can use either Maven Surefire or Failsafe plugin to execute the runners.

Parallel Execution in Cucumber using Maven Surefire Plugin

Step 1: Add Maven Surefire plugin

Add below code in plugins section of pom.xml. Replace the latest version from here

  • threadCount: The thread count in the above setting is 3 threads per core.
  • perCoreThreadCount: If you want this to be 3 threads across all cores set the perCoreThreadCount to false.
  • useUnlimitedThreads: To set the thread count to useUnlimitedThreads instead of specific number set useUnlimitedThreads to true. 
  • parallel: In case of multiple runners one can also set the parallel option to classesAndMethods or classes in addition to methods.

Step 2: Use Maven command to run

Use the Maven test or a suitable command to execute the POM. This should run in parallel threaded mode.

$ mvn test

Note: In JUnit the feature files are run in parallel rather than scenarios, which means all the scenarios in a feature file will be executed by the same thread.