1
votes

Recently I created a framework with Cucumber-JUnit where I am able to execute Scenarios in parallel (For now keeping one scenario per feature) without any issue.

Now I have a situation where some of the features has to run in parallel and some in sequence.

Is there any way that we can control with tags or any other configuration to choose which has to run in parallel or sequence?

Let me put some overview how it is currently

Parallel and its thread size controlled as per cucumber official documentation - Maven surefire

pom.xml

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <version>3.0.0-M5</version>
   <configuration>
       <parallel>methods</parallel>
       <threadCount>${threadSize}</threadCount>
       <perCoreThreadCount>false</perCoreThreadCount>
       </configuration>
</plugin>
        
        
        

CucumberRunner:

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"src/test/resources/features"},
        glue = {"com.tests.binding.steps"},
        tags = "@regression"
)
public class RunCucumberFeatures {

}

command using to run tests

mvn clean test -Dcucumber.filter.tags="${toExecute} and not (@smoke)" -DthreadCount=${ThreadSize} -Dcucumber.execution.dry-run="false"

For toExecute parameter - we pass multiple tags like @customerClaim or @employeeClaim

Now, In my case features with tags @employeeClaim should execute in parallel and tags with @customerClaim should execute in sequence.

Is it possible with current design or any other way?

1

1 Answers

0
votes

Is there any way that we can control with tags or any other configuration to choose which has to run in parallel or sequence?

Not with cucumber-junit and JUnit 4. However with JUnit 5 you can use the cucumber-junit-platform-engine and use JUnit 5s support for exclusive resources.

https://github.com/cucumber/cucumber-jvm/tree/main/junit-platform-engine

To synchronize a scenario on a specific resource, the scenario must be tagged and this tag mapped to a lock for the specific resource. A resource is identified by an arbitrary string and can be either locked with a read-write-lock, or a read-lock.

For example, the following tags:

Feature: Exclusive resources

   @reads-and-writes-system-properties
   Scenario: first example
      Given this reads and writes system properties
      When it is executed
      Then it will not be executed concurrently with the second example

   @reads-system-properties
   Scenario: second example
      Given this reads system properties
      When it is executed
      Then it will not be executed concurrently with the first example

with this configuration:

cucumber.execution.exclusive-resources.reads-and-writes-system-properties.read-write=java.lang.System.properties
cucumber.execution.exclusive-resources.reads-system-properties.read=java.lang.System.properties

when executing the first scenario tagged with @reads-and-writes-system-properties will lock the java.lang.System.properties resource with a read-write lock and will not be concurrently executed with the second scenario that locks the same resource with a read lock.

Note: The @ from the tag is not included in the property name. Note: For canonical resource names see junit5/Resources.java

So by making an exclusive resource for @customerClaim you can prevent these scenarios from running in parallel. However to the best of my knowledge JUnit 5 makes no guarantees made about the order of execution so they should still be independent from each other.