Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read ConfigurationParameters from properties file in classpath #1003

Closed
6 tasks done
marcphilipp opened this issue Aug 4, 2017 · 10 comments
Closed
6 tasks done

Read ConfigurationParameters from properties file in classpath #1003

marcphilipp opened this issue Aug 4, 2017 · 10 comments

Comments

@marcphilipp
Copy link
Member

marcphilipp commented Aug 4, 2017

Overview

The discussion in #905 has brought to light that some test authors would like to configure different default values for the test instance lifecycle etc. without being forced to annotate each and every test class.

ConfigurationParameters already allows one to specify parameters for test engines. It currently uses JVM system properties as a fallback mechanism if a requested parameter is not explicitly provided when building a discovery request. However, system properties need to be specified for every launch configuration in an IDE, etc. which is often cumbersome and repetitive.

So, in addition to explicit parameters and system properties, we should read configuration parameters from a classpath resource called junit-platform.properties that could look like this:

junit.jupiter.conditions.deactivate = org.junit.jupiter.*
junit.jupiter.extensions.autodetection.enabled = true
junit.jupiter.testinstance.lifecycle.default = per_class

Configuration Parameter Resolution

The lookup in LauncherConfigurationParametersfor a config parameter would check the following sources in this order:

  1. explicitly specified parameters
  2. system properties
  3. config file

So, only if a parameter is neither explicitly specified nor present as a system property, would it be read from the config file.

Deliverables

  • Read ConfigurationParameters from properties file in the classpath.
    • Ensure proper resolution order.
    • Log INFO message if properties file detected.
    • Update JavaDoc for ConfigurationParameters.
  • Document in the User Guide.
  • Document in the release notes.
@marcphilipp marcphilipp added this to the 5.1 Backlog milestone Aug 4, 2017
@sbrannen sbrannen changed the title Read default ConfigurationParameters from properties file on classpath Read ConfigurationParameters from properties file on classpath Aug 4, 2017
@sbrannen sbrannen changed the title Read ConfigurationParameters from properties file on classpath Read ConfigurationParameters from properties file in classpath Aug 4, 2017
@sbrannen sbrannen modified the milestones: 5.0 RC3, 5.1 Backlog Aug 4, 2017
@sbrannen
Copy link
Member

sbrannen commented Aug 4, 2017

Tentatively slated for 5.0 RC3 now, for potential inclusion prior to 5.0 GA.

@kcooney
Copy link
Member

kcooney commented Aug 4, 2017

What's the expected behavior if there are multiple junit-platform.properties files on the classpath? I can imagine third-party libraries accidentally including one in their jar.

Do we want a preferred format to specify settings that are package-specific? I can imagine developers wanting to change the default test lifecycle for a package tree for integration tests. Possibly a format similar to a logging properties file?

@sbrannen
Copy link
Member

in progress

@sbrannen
Copy link
Member

What's the expected behavior if there are multiple junit-platform.properties files on the classpath?

We will simply implement "first one wins" behavior.

I can imagine third-party libraries accidentally including one in their jar.

I don't foresee that as likely, and if it did occur that would be a bug in the third-party library.

FWIW, I have never heard of any such issues with Spring's spring.properties file, and that's analogous to what we aim to support here.

@sbrannen
Copy link
Member

Do we want a preferred format to specify settings that are package-specific?

The goal of this issue is simply to provide a straightforward means for setting configuration parameters on the JUnit Platform using a persistent format: we are not addressing any of the existing configuration parameters supported by JUnit Jupiter in this issue.

I can imagine developers wanting to change the default test lifecycle for a package tree for integration tests. Possibly a format similar to a logging properties file?

If we want to support test instance lifecycle configuration at the package level, I think we should address that as a separate issue and simply look up @TestInstance on packages.

@sbrannen
Copy link
Member

FYI: the code is done and available here: 3e9376b

All that's left is documentation. 😉

sbrannen added a commit to sbrannen/junit5 that referenced this issue Aug 13, 2017
@kcooney
Copy link
Member

kcooney commented Aug 14, 2017

I can imagine third-party libraries accidentally including one in their jar.

I don't foresee that as likely, and if it did occur that would be a bug in the third-party library.
FWIW, I have never heard of any such issues with Spring's spring.properties fil

@sbrannen FWIW, it seems to be quite common for logging properties files:

I suggest using ClassLoader.findResources() to find the property file, and log a warning if there is more than one instance on the classpath.

@sbrannen
Copy link
Member

I suggest using ClassLoader.findResources() to find the property file, and log a warning if there is more than one instance on the classpath.

Alrighty. I'll see if I can make it a bit more robust.

Cheers,

Sam

@sbrannen
Copy link
Member

@kcooney, I switched to using ClassLoader.getResources() (ClassLoader.findResources() is a protected method 😉) in my most recent commit (4d9b029).

sbrannen added a commit that referenced this issue Aug 14, 2017
Prior to this commit, configuration parameters could only be set via
the LauncherDiscoveryRequestBuilder or JVM system properties; however,
neither of these options were robust solutions for repeatable builds
with regards to configuration parameters such as JUnit Jupiter's
'junit.jupiter.testinstance.lifecycle.default' that alter the manner in
which tests are executed.

This commit addresses this issue by introducing support for supplying
_configuration parameters_ via a file named 'junit-platform.properties'
in the root of the class path. Consult the new 'Configuration
Parameters' section of the User Guide for further details.

Issue: #1003
sbrannen added a commit that referenced this issue Aug 14, 2017
Prior to this commit, configuration parameters could only be set via
the LauncherDiscoveryRequestBuilder or JVM system properties; however,
neither of these options were robust solutions for repeatable builds
with regards to configuration parameters such as JUnit Jupiter's
'junit.jupiter.testinstance.lifecycle.default' that alter the manner in
which tests are executed.

This commit addresses this issue by introducing support for supplying
configuration parameters via a file named 'junit-platform.properties'
in the root of the class path. Consult the new 'Configuration
Parameters' section of the User Guide for further details.

Issue: #1003
@sbrannen
Copy link
Member

Resolved in master in commit df92b77.

@ghost ghost removed the status: in progress label Aug 14, 2017
sdeleuze added a commit to sdeleuze/spring-kotlin-functional that referenced this issue Aug 15, 2017
Andrei94 pushed a commit to Andrei94/junit5 that referenced this issue Jun 23, 2018
Prior to this commit, configuration parameters could only be set via
the LauncherDiscoveryRequestBuilder or JVM system properties; however,
neither of these options were robust solutions for repeatable builds
with regards to configuration parameters such as JUnit Jupiter's
'junit.jupiter.testinstance.lifecycle.default' that alter the manner in
which tests are executed.

This commit addresses this issue by introducing support for supplying
configuration parameters via a file named 'junit-platform.properties'
in the root of the class path. Consult the new 'Configuration
Parameters' section of the User Guide for further details.

Issue: junit-team#1003
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants