Description
Overview
As discussed in #905 (comment), there is currently no native support for setting a configuration parameter via the console launcher, Maven Surefire plugin, or Gradle plugin.
Thus, the only option from the build perspective is to set a system property or rely on the presence of a JUnit Platform configuration file (see #1003).
For the JUnit Platform Gradle Plugin, you can set such a system property via a work-around that is discussed in #475 (comment).
Proposal
ConsoleLauncher
Introduce a --config
command line option that expects a key=value
pair.
java -jar junit-platform-console-standalone-*.jar \
--config junit.jupiter.extensions.autodetection.enabled=true \
--config junit.jupiter.testinstance.lifecycle.default=per_class
Gradle
Align with the syntax supported for JVM system properties by Gradle tasks:
systemProperty('java.util.logging.manager', 'org.apache.logging.log4j.jul.LogManager')
This gives us:
junitPlatform {
// ...
configurationParameter('junit.jupiter.extensions.autodetection.enabled', 'true')
configurationParameter('junit.jupiter.testinstance.lifecycle.default', 'per_class')
// ...
}
Note, however, that the parentheses are optional in Groovy resulting in the following alternative syntax being supported out of the box.
junitPlatform {
// ...
configurationParameter 'junit.jupiter.extensions.autodetection.enabled', 'true'
configurationParameter 'junit.jupiter.testinstance.lifecycle.default', 'per_class'
// ...
}
Maven
Surefire does not support nested structures within properties
, but that's not an issue if we take inspiration from Spring's support for inlined Properties
in XML configuration, resulting in the following.
// ...
<build>
<plugins>
// ...
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<properties>
<excludeTags>integration, regression</excludeTags>
<configurationParameters>
junit.jupiter.extensions.autodetection.enabled = true
junit.jupiter.testinstance.lifecycle.default = per_class
</configurationParameters>
</properties>
</configuration>
<dependencies>
// ...
</dependencies>
</plugin>
</plugins>
</build>
// ...
For an example of how the configurationParameters
can be converted to a Map<String, String>
with full support for the java.util.Properties
syntax, see #1015 (comment).
Deliverables
- Introduce support for setting configuration parameters in the console launcher.
- Introduce support for setting configuration parameters in the JUnit Platform Gradle Plugin.
- Introduce support for setting configuration parameters in the Maven Surefire Plugin.
- Update User Guide.
- Update release notes.
-
Prepare sample projects.