I have an application here where the unit tests are written in a way that they cannot be run in parallel.
When running the tests with maven some of them fail for that reason. I could verify that they are run in parallel by doing a
System.out.println(System.currentTimeMillis() +">>> executing testXXX");
System.out.println(System.currentTimeMillis() +">>> finished testXXX");
at the start and end of each method. The output is:
1530602546964>>> executing testInstantiation
1530602547036<<< finished testInstantiation
1530602547042>>> executing testSimilarNamedResources
1530602547050>>> executing testTranslateWithMissingKey
1530602547051>>> executing testTryTranslateWithMissingKey
1530602547051<<< finished testTryTranslateWithMissingKey
1530602547051>>> executing testTranslationMapWithMissingKey
1530602547055>>> executing testSilentlyIgnoringExceptionTranslationMapWithMissingKey
1530602547055<<< finished testSilentlyIgnoringExceptionTranslationMapWithMissingKey
As we can see after testSimilarNamedResources started, some other tests are started, too.
I tried to configure the surefire plugin to not run in parallel:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<!--parallel>false</parallel-->
<threadCount>1</threadCount>
<perCoreThreadCount>false</perCoreThreadCount>
</configuration>
</plugin>
</plugins>
</build>
But it still executes these tests in paralled.
I ran mvn with the -X
option to see whether my configuration was applied and got this output:
$ mvn -X test | grep -iE "(parallel|threadcount)"
<parallel>${parallel}</parallel>
<parallelMavenExecution default-value="${session.parallel}"/>
<parallelOptimized default-value="true">${parallelOptimized}</parallelOptimized>
<parallelTestsTimeoutForcedInSeconds>${surefire.parallel.forcedTimeout}<parallelTestsTimeoutForcedInSeconds>
<parallelTestsTimeoutInSeconds>${surefire.parallel.timeout}<parallelTestsTimeoutInSeconds>
<perCoreThreadCount default-value="true">false</perCoreThreadCount>
<threadCount>0</threadCount>
<threadCountClasses default-value="0">${threadCountClasses}</threadCountClasses>
<threadCountMethods default-value="0">${threadCountMethods}</threadCountMethods>
<threadCountSuites default-value="0">${threadCountSuites}</threadCountSuites>
[DEBUG] (f) parallelMavenExecution = false
[DEBUG] (s) parallelOptimized = true
[DEBUG] (s) perCoreThreadCount = false
[DEBUG] (s) threadCount = 0
[DEBUG] (s) threadCountClasses = 0
[DEBUG] (s) threadCountMethods = 0
[DEBUG] (s) threadCountSuites = 0
Do I miss something in the plugin configuration?
UPDATE:
I have given up. The behaviour was too strange. Trying to create simple sample didn't work. Those tests were not run in parallel. I didn't found out why this was the case here. We will revamp the whole code and therefore also the unit tests. Not need to find a solution anymore, but it still puzzles me why it showed this strange behaviour…
> [DEBUG] (f) parallelMavenExecution = false
. Please provide a Minimal, Complete, and Verifiable example. – Inelegant