I'm using the maven-surefire plugin to execute the Cucumber Runner in parallel. In each of the Runners, I'm invoking a synchronized static method of a Utilities class. But all the Runners running in parallel are able to invoke the method in a non-synchronized way.
@RunWith(CucumberWithSerenity.class)
@CucumberOptions(...)
public class SampleRunner {
@BeforeClass
public static void loadLocators() {
Utilities.doSomething();
}
}
public class Utilities {
public synchronized static void doSomething() {
System.out.println("Start");
.
.
.
System.out.println("Stop");
}
}
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<includes>
<include>**/*Runner.java</include>
</includes>
<parallel>classes</parallel>
<threadCount>${parallel.tests}</threadCount>
<forkCount>${parallel.tests}</forkCount>
<perCoreThreadCount>true</perCoreThreadCount>
<!-- <skip>true</skip> -->
</configuration>
</plugin>
And when I have the threadCount as say 3, and execute mvn clean verify serenity:aggregate
I get the following logs
Start
Start
Stop
Stop
Start
Stop
What I am Expecting is
Start
Stop
Start
Stop
Start
Stop