-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Support multiple junit-platform.properties
on the classpath
#2794
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Hi @marcphilipp, may I ask whether the team had time to discuss this? |
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? |
There is no parent pom in Quarkus but a BOM instead (which cannot transport plugin config). PS: ...and there is also Gradle. |
We were just bitten by this as well. Our project (transitively) depends on #replaces the need to set @TestInstance(TestInstance.Lifecycle.PER_CLASS) on every test class
junit.jupiter.testinstance.lifecycle.default=per_class
👍 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 |
@famod Sorry for taking so long to get back to you. We finally got around to discussing this issue in the team. I'll follow-up with some brainstorming ideas what we can discuss here. |
Supporting multiple Idea 1: Separate "default" properties filesInstead of supporting multiple Idea 2: Importsimports=/META-INF/quarkus/junit-platform.properties,... To avoid having to copy the values from Quarkus' properties file which could get outdated when updating Quarkus, a special Idea 3: ServiceLoader-like indirectionA new Those providers could be registered via Alternatively, they could be registered or filtered in junit.platform.properties.providers.includes=org.quarkus.junit.QuarkusJUnitPropertyProvider If anyone else has other suggestions, please let us know. |
Idea 1This approach would limit JUnit to 2 properties files. Idea 2This seems the easiest to understand and most flexible. Properties are loaded and applied based on the order listed in
Idea 3Writing code to load properties ( |
A burden for whom? Only for JUnit team members and library authors (like Quarkus) that want to provide tailored (default) properties (overrides). |
@dhoard, perhaps it's not clear from the explanation, but that's not correct. Idea 1 would find all |
What I think we are trying to achieve isn't really about merging properties. Rather it is about seamless configuration based on the available dependencies. Something like Spring Boots auto configuration. And with that in mind, there are only a handful of properties for which it would make sense to auto configure something.
With a |
@sbrannen @mpkorstanje thanks for the clarification. |
I wasn't clarifying. That was a different proposal. 😉 |
I can think of only this one being an issue (what are the others?). Hence, I want to propose Idea 4: Aggregation without auto-mergingCollect all
Issues with other proposalsHere's why I prefer my approach. Idea 1:Forcing library authors to use Idea 2:I may not even know that some of my dependencies include their own Idea 1:Pretty much the same concern as with idea 1. |
@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 I'm aware that this is definitely the Achilles' heel of my proposal. I don't have a perfect proposal I'm afraid. In a way, my proposal is (in terms of responsibility) the inverse of Idea 1 : rather than forcing all library authors to move their props file, it asks the application author to somehow mark/tag or otherwise identify their own file. I guess if you detect a props file on a filesystem classpath you can safely assume that this must the one, right? Is it realistic to have multiples of those? If it's packaged into a JAR it becomes impossible for JUnit to reliably detect my own file without any hints I think. Can I be asked to add "something" (a comment?) to my file to identify it as mine? |
In a multi-project setup, it's quite common for it to be in a JAR when shared across projects.
How many are we talking about? I'm only aware of Quarkus shipping a properties file. |
If you would like us to be able to process this issue, please provide the requested information. If the information is not provided within the next 3 weeks, we will be unable to proceed and this issue will be closed. |
Kafka seems to be shipping with such a file in its jars as well.
|
But why? For the following? junit.jupiter.params.displayname.default = "{displayName}.{argumentsWithNames}" Similar/same line in: https://github.com/apache/kafka/blob/trunk/server-common/src/test/resources/junit-platform.properties |
Those don't look like they're meant for consumption in downstream projects, do they? |
I can't say why, honestly :D It looks quite useless to me, to be honest, but it's there. Idea 5: Strip out the file manuallyI don't really like it (I would prefer some sort of merging done automatically) but, for Maven builds, https://www.mojohaus.org/truezip/truezip-maven-plugin/ could be used to strip out the file from the jars. |
I agree. |
@sbrannen A naïve idea would be to assign the priority based on the path where the files have been found. Moreover, configs within JARs (aka from some sort of direct or transitive dependency) could have less priority by default. |
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 |
@mumrah Yes, that sounds like a sensible solution. Another would be to exclude |
@mumrah I would probably simply adapt the Gradle task responsible of creating the test-jar to not include such a file as @marcphilipp said. 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. |
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. |
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. withjunit.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-L236Btw, 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 repeatingjunit.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?).
The text was updated successfully, but these errors were encountered: