Skip to content

Support multiple junit-platform.properties on the classpath #2794

Description

@famod

I implemented a ClassOrderer for Quarkus and the idea was to enable that orderer by default for all Quarkus users (and also for the Quarkus CI).
But I overlooked the fact that junit-platform.properties is only expected once on the classpath and if there already is a project-specific properties file (e.g. with junit.jupiter.extensions.autodetection.enabled) there are many warnings issued by this code: https://github.com/junit-team/junit5/blob/r5.8.2/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/LauncherConfigurationParameters.java#L232-L236

Btw, that orderer is configurable, so the original idea also was to just add (as a Quarkus user) a custom junit-platform.properties to your project with only the respective property (without repeating junit.jupiter.testclass.order.default).

It would come in very handy if all junit-platform.properties on the classpath would be merged, in the order as they appear on the cp.
I'm not sure whether a flag to go back to the previous behavior would be required, which is a bit of a chicken and egg situation I guess (where to put it?).

Activity

  1. famod commented on Dec 12, 2021

    @famod
    Author
  2. stale commented on Dec 13, 2022

    @stale
  3. stefanrybacki commented on Dec 13, 2022

    @stefanrybacki
  4. famod commented on Jan 30, 2023

    @famod
    Author
  5. mpkorstanje commented on Jan 31, 2023

    @mpkorstanje
    Member

    Note: Not part of the JUnit team.

    It seems to me that depending on the classpath order to determine the configuration of JUnit is fraught with unpredictability and would make it hard to reason about the effective configuration.

    However the JUnit Platform accepts configuration from a few different sources, the properties file being only one of them.

    Now I'm not familiar with Quarkus but I would expect that all projects inherit from some parent-pom. Have you considered providing the property through Surefire instead?

  6. famod commented on Jan 31, 2023

    @famod
    Author

    Now I'm not familiar with Quarkus but I would expect that all projects inherit from some parent-pom. Have you considered providing the property through Surefire instead?

    There is no parent pom in Quarkus but a BOM instead (which cannot transport plugin config).
    Generated apps could be covered this way, but:
    a) not everyone uses that generation
    b) there are many existing projects out there
    c) surefire config is not picked automatically in Eclipse IDE (and maybe others)

    PS: ...and there is also Gradle.

  7. marcelstoer commented on Jan 3, 2024

    @marcelstoer

    We were just bitten by this as well. Our project (transitively) depends on io.quarkus:quarkus-junit5-properties which ships a junit-platform.properties (source). This now clashes with our own file.

    #replaces the need to set @TestInstance(TestInstance.Lifecycle.PER_CLASS) on every test class
    junit.jupiter.testinstance.lifecycle.default=per_class

    It seems to me that depending on the classpath order to determine the configuration of JUnit is fraught with unpredictability

    👍

    This is particularly so as the JUnit guide warns "It is therefore recommended to change the default in the JUnit Platform configuration file instead of via a JVM system property."

    At the moment, the only sensible remedy appears to be to exclude the Quarkus dependency and to copy-paste their JUnit instructions into our junit-platform.properties.

  8. 28 remaining items

  9. cdprete commented on Aug 9, 2024

    @cdprete

    Those don't look like they're meant for consumption in downstream projects, do they?

    I agree.
    In the meantime, I've opened a ticket on their issue tracker: https://issues.apache.org/jira/browse/KAFKA-17307 with https://github.com/cdprete/kafka-junit-platform-props as minimal example.

  10. cdprete commented on Aug 9, 2024

    @cdprete

    Collect all junit-platform.properties from the classpath but give precedence to my own.

    @marcelstoer, how do you propose that JUnit should detect which one is "your own"?

    Please keep in mind that developers may choose to package their own properties file in a JAR and that the structure of the classpath (filesystem directories, JARs, exploded JARs, etc). may be different in the build vs. in the IDE, etc.

    @sbrannen A naïve idea would be to assign the priority based on the path where the files have been found.
    The further they're away from the current working (or, better, sub-module in case of multi-module projects) directory, the less important they're.
    In such a scenario, "your own" file will be the one having the shortest path.

    Moreover, configs within JARs (aka from some sort of direct or transitive dependency) could have less priority by default.

  11. mumrah commented on Sep 17, 2024

    @mumrah

    Hello from Apache Kafka 👋 😄. I came across this thread while trying to figure out why we were seeing this warning in our build. I agree we should not be shipping this file in our test jars (I upgraded the priority of KAFKA-17307).

    What we were attempting to do was set a default JUnit property for all of our tests. What is the recommended approach here? We have a multi-project Gradle build with a fairly complex tree of dependencies. Perhaps we need to introduce a testRuntimeOnly project dependency that includes this file as a resource?

  12. marcphilipp commented on Sep 23, 2024

    @marcphilipp
    Member

    @mumrah Yes, that sounds like a sensible solution. Another would be to exclude junit-platform.properties when creating the test jar.

  13. cdprete commented on Sep 26, 2024

    @cdprete

    Hello from Apache Kafka 👋 😄. I came across this thread while trying to figure out why we were seeing this warning in our build. I agree we should not be shipping this file in our test jars (I upgraded the priority of KAFKA-17307).

    What we were attempting to do was set a default JUnit property for all of our tests. What is the recommended approach here? We have a multi-project Gradle build with a fairly complex tree of dependencies. Perhaps we need to introduce a testRuntimeOnly project dependency that includes this file as a resource?

    @mumrah I would probably simply adapt the Gradle task responsible of creating the test-jar to not include such a file as @marcphilipp said.
    This should be even safer for Maven projects since there is no test-runtime scope in Maven.

    Another option would maybe be to configure the Gradle test runner to pass these properties as system properties, so that the file is not needed at all.

  14. mumrah commented on Sep 26, 2024

    @mumrah

    Turns out, this was solved a little while ago in Kafka (KAFKA-17121) by explicitly excluding the file from the JARs. In the upcoming 3.9 release, this should no longer be a problem.

  15. seregamorph commented on Dec 23, 2024

    @seregamorph

    How many are we talking about? I'm only aware of Quarkus shipping a properties file.

    Facing the same problem with https://github.com/seregamorph/spring-test-smart-context/blob/master/spring-test-smart-context/src/main/resources/junit-platform.properties
    This project defines own sorter of spring integration test classes grouped sequentially by their context configurations (and eagerly closing context on last test per each config). The idea is pretty similar to what @famod explains in the topic starting message and by design the project using this micro-framework just needs to declare a single dependency without any other special configuration, that's it.

    As a failover logic for now I plan to make auto-diagnostics that will detect multiple junit-platform.properties and give guidance. But in general it would be great to have some generic solution there.

  16. marcphilipp commented on Jan 2, 2025

    @marcphilipp
    Member

    @seregamorph Thanks for sharing that use case! In your case you'd probably want that to be used but be able to override the sorter for your tests, if necessary, right?

  17. seregamorph commented on Jan 2, 2025

    @seregamorph

    The project provides its own junit-platform.properties in the classpath to auto-configure the test sorting, yes. And this sorting is mandatory, because this way the library discovers the full set of test classes (which should be known ahead before executing them). So the basic instruction is simple: just add a dependency and all the magic will happen automatically (it also discovers spring test execution listeners from spring.factories).
    But what can happen in a project that has own junit-platform.properties or it potentially comes from another third-party like spring-kafka-test (even if these configurations don't conflict to each other as they declare different parameters): the sorting is not applied (but it's a key feature for the library to properly sort tests) and in the best case there will be a warning from junit-platform core about duplication. But as you understand, for library user it can be not very helpful.

    This is especially possible in a huge codebase, where the optimization with test reordering and eager context closing makes the best possible effect (actually that's how I discovered the problem - just added a library to Adyen codebase :) ).

  18. holly-cummins commented on Jun 4, 2025

    @holly-cummins

    I suspect that in many cases the properties in the two files would not conflict (except for maybe class orderers). Maybe the best solution is to still print a warning, but also aggregate the contents of the two files? This isn't perfect, but it avoids the case where one of the files is completely ignored. I'd be happy to do a PR if that solution is agreeable.

  19. holly-cummins commented on Apr 14, 2026

    @holly-cummins

    I've created #5559, which I think resolves this relatively safely. The behaviour preserves the current behaviour when individual properties conflict, but ensures that the presence of a junit-platform.properties file in a dependency doesn't stop a project's properties from being read.

  20. marcphilipp commented on Apr 20, 2026

    @marcphilipp
    Member

    We discussed this issue in last week's team call.

    We're aligned on the following design goals:

    1. Test authors should ultimately be in control of JUnit's configuration: they need a mechanism to override any defaults a framework such as Quarkus, Spring, etc. provides
    2. Frameworks should be able to provide defaults reliably: they should not stop working when a user configures an unrelated configuration parameter (as it would happen today with a local junit-platform.properties).
    3. Test authors should be able to see the effective configuration and be able to reason about its sources.
    4. Backward compatibility: (most) existing setups (e.g. with multiple properties files on the classpath) should keep working

    We're not convinced that merging multiple junit-platform.properties files is the right solution or at least not yet. Before working towards a general solution (which may or may not be merging properties), we'd like to focus on the use case of supporting default ClassOrderers. @sbrannen will pick that up in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions