JUnit 5 tests are executed in parallel inside IntelliJ and locally with Maven, but not inside Maven Docker container on Google Cloud Build

Viewed 2058

I am using JUnit 5 in my Maven project.

My junit-platform.properties looks like this:

junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=concurrent

When running the tests inside IntelliJ or with Maven locally, the test are executed in parallel.

However, when running them on Cloud Build inside a Maven Docker container, they seem to run sequentially.

This is how they are called:

steps:
  - name: 'maven:3-jdk-11-slim'
    args: [
      'mvn',
      # https://stackoverflow.com/a/53513809/3067148
      '-Dorg.slf4j.simpleLogger.showDateTime=true',
      '-Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss,SSS',
      '-B',
      'test'
    ]

What could be the reason why they aren't executed in parallel?

1 Answers

Properties such as the desired parallelism and the maximum pool size can be configured using a ParallelExecutionConfigurationStrategy. The JUnit Platform provides two implementations out of the box: dynamic and fixed. Alternatively, you may implement a custom strategy.

Keep in mind that the ParallelExecutionConfigurationStrategy class is still in the "EXPERIMENTAL" state and it is not yet stable. Unintended behaviour may occur.

As you don't set a specific configuration strategy, the following section applies:

If no configuration strategy is set, JUnit Jupiter uses the dynamic configuration strategy with a factor of 1. Consequently, the desired parallelism will be equal to the number of available processors/cores.

Find more details at https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution-config

Related