which of these? it doesn't feel like I should have...
# community-support
c
which of these? it doesn't feel like I should have both "junit" defs
Copy code
testing {
  suites {
    withType<JvmTestSuite>().configureEach {
      useJUnitJupiter()
Copy code
tasks.withType<Test>().configureEach {
  useJUnitPlatform()
s
The latter should be enough, quoting this:
Note that all suites other than the built-in
test
suite will by convention work as if
useJUnitJupiter()
was called.
👍 1
v
Those two are different. The first also adds the Jupiter engine and the Jupiter api. The second only configures JUnit Platform to be used. Which to use probably depends on your view on incubating features. I prefer using the new JVM test suite DSL. But well, it is incubating officially.
c
engine and api? meaning it probably removes some dependencies from my bundle? after they removed ... platform launcher? from the default test when you add platform?
not certain if that's better or going back to something that was decided was a bad idea
although it also sounds like it would control which version of junit I'm using
how does that interact with the spring bom?
v
I did not really get what you are saying.
useJUnitPlatform()
just means use the JUnit 5 platform to launch tests
useJupiter()
means use the JUnit 5 platform to launch tests, add the Jupiter engine so that Jupiter tests are found, and add the Jupiter API so that you can code the tests using Jupiter The version used are hard-coded defaults, or you can give them as argument to those methods. It should work with the Spring BOM like any other dependency.
c
right, that's basically some of this
Copy code
junit-api = { module = "org.junit.jupiter:junit-jupiter-api" }
junit-bom = "org.junit:junit-bom:5.+"
junit-parameters = { module = "org.junit.jupiter:junit-jupiter-params" }
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine" }
junit-launcher = { module = "org.junit.platform:junit-platform-launcher" }
am I wrong? how does it know what version to use? spring boot adds a version for this, obviously I'm resolving my own (I forget why, but I am increasingly untrusting of spring boot's dependency decisions)
v
I think it should be all of that except for
junit-parameters
, but I use Spock for tests everywhere, that is what makes testing fun again. 🙂
Regarding the version, what is unclear from what I said?
c
because 5 is a top level version... not a specific one
features and bugs are fixed
v
?
c
so if I added -params, how would I know what version I was going to get
how would I know it's compatible
v
As I said, if you don't give a version, it uses a hard-coded default. If you give one as argument, that is used. And either way you can still manually define the bom version or a constraint or form another bom or whatever. It just adds some dependencies for you just like you would do manually
so if I added -params, how would I know what version I was going to get
Probably depends on whether JUnit properly published version alignment metadata
c
so if I add a bom to my dependencies it would override that magically?
v
If so it should just work, if not you could do it in your build too
c
that's what the junit-bom above is
v
Not necessarily
A BOM is not aligning by default
c
well... it's better than not, I guess...
v
Let me give an example
c
bug go ahead and explain that statement 😉
v
Assume modules A and B and according BOM, all released in version 1 and 2
Without BOM and without alignment if you depend on A:1 and B:2 you end up with A:1 and B:2.
Without BOM and without alignment if you depend on A:1 and B it does not work.
With BOM and without alignment if you depend on A:1 and B:2 you end up with A:1 and B:2.
With BOM and without alignment if you depend on A:1 and B you end up with A:1 and B:1.
c
but with platform(bom) why would I add a version for A and B?
v
Without proper alignment metadata if you depend on A:1 and B:2 you end up with A:2 and B:2.
Because it might not be you adding that dependency. If you depend on something else that depends on A, that transitive A might have a version. Using
useJupiter()
is practically that.
c
right, reasons why I think the new thing is probably not a good idea.. not much effort there to be explicit. Good to know
I'm going to leave a comment in my code
v
You can for example use Groovy modules as an example. With Groovy 4, there are proper alignment metadata published. With Groovy 2.5, there was a BOM, but no alignment metadata published.
c
right
basically this might give me the same problem spring starters do... especially when they behave like a BOM themselves but don't use upstreams bom...
alignment or not
see violating the jakarta EE spec issue where they refuse to add dependencies that jakarta ee transaction says they require (might be a spec issue, but it is what it is)
an issue that wouldn't happen if they used the jakarta ee bom, or just didn't add transaction in their starter
because I don't even use that library
v
🤷‍♂️
c
thanks for the information, but experience tells me that I don't want that behavior
tbh, you don't seem to be telling me the right way to add -parameters and how that'd interact safely with the builtins, so that alone is a red flag
essentially yeah, I"ve had 2 bad experiences with this kind of thing lately
also didn't like the look of the spock api...lol
v
tbh, you don't seem to be telling me the right way to add -parameters and how that'd interact safely with the builtins, so that alone is a red flag
It just means I'm not using Jupiter
c
seems like you wouldn't want this behavior because it would add a jar to your implementation that you don't want (the api)
v
Copy code
testing {
    suites {
        val test by existing(JvmTestSuite::class) {
            useJUnitJupiter("5.+")
            dependencies {
                implementation("org.junit.jupiter:junit-jupiter-params")
            }
        }
    }
}
seems like you wouldn't want this behavior because it would add a jar to your implementation that you don't want (the api)
Why would you not want the api? Without you cannot write any tests
And actually, it does not add the api directly, it just comes in transitively through the jupiter dependency
c
I don't remember how spock works, also I assume you don't need the api if you're doing kotlin/groovy tests... but I could be wrong. I only use jupiter directly
what jupiter dependency?
v
Copy code
testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- org.junit.jupiter:junit-jupiter-params -> 5.11.0-RC1
|    +--- org.junit:junit-bom:5.11.0-RC1
|    |    +--- org.junit.jupiter:junit-jupiter:5.11.0-RC1 (c)
|    |    +--- org.junit.jupiter:junit-jupiter-api:5.11.0-RC1 (c)
|    |    +--- org.junit.jupiter:junit-jupiter-engine:5.11.0-RC1 (c)
|    |    +--- org.junit.jupiter:junit-jupiter-params:5.11.0-RC1 (c)
|    |    +--- org.junit.platform:junit-platform-launcher:1.11.0-RC1 (c)
|    |    +--- org.junit.platform:junit-platform-commons:1.11.0-RC1 (c)
|    |    \--- org.junit.platform:junit-platform-engine:1.11.0-RC1 (c)
|    \--- org.junit.jupiter:junit-jupiter-api:5.11.0-RC1
|         +--- org.junit:junit-bom:5.11.0-RC1 (*)
|         +--- org.opentest4j:opentest4j:1.3.0
|         \--- org.junit.platform:junit-platform-commons:1.11.0-RC1
|              \--- org.junit:junit-bom:5.11.0-RC1 (*)
+--- org.junit.jupiter:junit-jupiter:5.+ -> 5.11.0-RC1
|    +--- org.junit:junit-bom:5.11.0-RC1 (*)
|    +--- org.junit.jupiter:junit-jupiter-api:5.11.0-RC1 (*)
|    +--- org.junit.jupiter:junit-jupiter-params:5.11.0-RC1 (*)
|    \--- org.junit.jupiter:junit-jupiter-engine:5.11.0-RC1
|         +--- org.junit:junit-bom:5.11.0-RC1 (*)
|         +--- org.junit.platform:junit-platform-engine:1.11.0-RC1
|         |    +--- org.junit:junit-bom:5.11.0-RC1 (*)
|         |    +--- org.opentest4j:opentest4j:1.3.0
|         |    \--- org.junit.platform:junit-platform-commons:1.11.0-RC1 (*)
|         \--- org.junit.jupiter:junit-jupiter-api:5.11.0-RC1 (*)
\--- org.junit.platform:junit-platform-launcher -> 1.11.0-RC1
     +--- org.junit:junit-bom:5.11.0-RC1 (*)
     \--- org.junit.platform:junit-platform-engine:1.11.0-RC1 (*)
c
lol, gods... I wonder if it respects my rules to not do pre-release, I filter those
so the only reason you're getting api is because you added parameters?
v
Again, it is normal dependency resolution, if it works with normal dependencies, it works here too
c
oh, I missed that, lool, oops
v
And yes, JUnit 5 also properly publishes alignment metadata.
Copy code
useJUnitJupiter("5.9.0")
dependencies {
    implementation("org.junit.jupiter:junit-jupiter-params:5.10.0")
}
Uses 5.10.0 for everything.
So no real need to use the bom anywhere explicitly
As long as you somewhere get a version from for at least one of the modules
c
at least I'm not supposed to have the RC dependency...
but I do
v
How did you try to avoid it?
c
guess I didn't add that to my pattern...
Copy code
resolutionStrategy {
    componentSelection {
      all {
        val nonRelease = Regex("^[\\d.]+-(RC|M|ea|beta|alpha).*$")
        val module = Regex("^spotbugs.*")
        val group = Regex("^com.xenoterracide$")
        if (!candidate.group.matches(group) && !name.matches(module) && !candidate.module.matches(module)) {
          if (candidate.version.matches(nonRelease)) reject("no pre-release")
          if (candidate.version.endsWith("-SNAPSHOT")) reject("no snapshots")
        } else if (candidate.version.matches(nonRelease)) {
          <http://logger.info|logger.info>("allowing: {}", candidate)
        }
I just added
RC
v
yeah, well, if you missed the
.*
then it's clear. 😄 Like shown it works fine.
c
yeah, before it was just
...(M|...
it works if I actually exclude it 😉
btw, somewhere I have it and don't know why... but
junit-jupiter
doesn't actually exist in most of my modules
or at least some of them that do use Junit 5 jupiter engine
not certain what that jar/pom is
lazy, meh
v
Sorry, didn't get what you are saying
What is where missing or not or what?
c
at least in some of my modules... this returns nothing
Copy code
./gradlew :jpa:dependencyInsight --configuration testRuntimeClasspath --dependency junit-jupiter | grep "junit-jupiter:"
without the grep
Copy code
Reusing configuration cache.

> Task :jpa:dependencyInsight
org.junit.jupiter:junit-jupiter-api:5.10.3
  Variant runtimeElements:
    | Attribute Name                     | Provided     | Requested    |
    |------------------------------------|--------------|--------------|
    | org.gradle.status                  | release      |              |
    | org.jetbrains.kotlin.platform.type | jvm          |              |
    | org.gradle.category                | library      | library      |
    | org.gradle.dependency.bundling     | external     | external     |
    | org.gradle.jvm.environment         | standard-jvm | standard-jvm |
    | org.gradle.jvm.version             | 8            | 21           |
    | org.gradle.libraryelements         | jar          | jar          |
    | org.gradle.usage                   | java-runtime | java-runtime |
   Selection reasons:
      - By constraint: dependency was locked to version '5.10.3'
      - By ancestor

org.junit.jupiter:junit-jupiter-api:{strictly 5.10.3} -> 5.10.3
\--- project :jpa
     \--- project :jpa (*)

org.junit.jupiter:junit-jupiter-api:5.10.3
+--- org.junit:junit-bom:5.10.3
|    +--- project :jpa (requested org.junit:junit-bom:5.+)
|    |    \--- project :jpa (*)
|    +--- org.junit.jupiter:junit-jupiter-params:5.10.3
|    |    +--- project :jpa (requested org.junit.jupiter:junit-jupiter-params) (*)
|    |    +--- org.springframework.boot:spring-boot-dependencies:3.3.2
|    |    |    +--- project :jpa (requested org.springframework.boot:spring-boot-dependencies:3.+) (*)
|    |    |    +--- project :model (requested org.springframework.boot:spring-boot-dependencies:3.+)
|    |    |    |    \--- project :jpa (*)
|    |    |    \--- project :test-app (requested org.springframework.boot:spring-boot-dependencies:3.+)
|    |    |         \--- project :jpa (*)
|    |    \--- org.junit:junit-bom:5.10.3 (*)
|    +--- org.junit.jupiter:junit-jupiter-engine:5.10.3
|    |    +--- project :jpa (requested org.junit.jupiter:junit-jupiter-engine) (*)
|    |    +--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)
|    |    \--- org.junit:junit-bom:5.10.3 (*)
|    +--- org.junit.jupiter:junit-jupiter-api:5.10.3 (*)
|    +--- org.junit.platform:junit-platform-launcher:1.10.3
|    |    +--- project :jpa (requested org.junit.platform:junit-platform-launcher) (*)
|    |    +--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)
|    |    \--- org.junit:junit-bom:5.10.3 (*)
|    +--- org.junit.platform:junit-platform-engine:1.10.3
|    |    +--- project :jpa (requested org.junit.platform:junit-platform-engine:{strictly 1.10.3}) (*)
|    |    +--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)
|    |    +--- org.junit.jupiter:junit-jupiter-engine:5.10.3 (*)
|    |    +--- org.junit.platform:junit-platform-launcher:1.10.3 (*)
|    |    \--- org.junit:junit-bom:5.10.3 (*)
|    \--- org.junit.platform:junit-platform-commons:1.10.3
|         +--- project :jpa (requested org.junit.platform:junit-platform-commons:{strictly 1.10.3}) (*)
|         +--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)
|         +--- org.junit.jupiter:junit-jupiter-api:5.10.3 (*)
|         +--- org.junit.platform:junit-platform-engine:1.10.3 (*)
|         \--- org.junit:junit-bom:5.10.3 (*)
+--- org.junit.jupiter:junit-jupiter-engine:5.10.3 (*)
+--- org.junit.jupiter:junit-jupiter-params:5.10.3 (*)
\--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)

org.junit.jupiter:junit-jupiter-api -> 5.10.3
\--- project :jpa
     \--- project :jpa (*)

org.junit.jupiter:junit-jupiter-engine:5.10.3
  Variant runtimeElements:
    | Attribute Name                     | Provided     | Requested    |
    |------------------------------------|--------------|--------------|
    | org.gradle.status                  | release      |              |
    | org.jetbrains.kotlin.platform.type | jvm          |              |
    | org.gradle.category                | library      | library      |
    | org.gradle.dependency.bundling     | external     | external     |
    | org.gradle.jvm.environment         | standard-jvm | standard-jvm |
    | org.gradle.jvm.version             | 8            | 21           |
    | org.gradle.libraryelements         | jar          | jar          |
    | org.gradle.usage                   | java-runtime | java-runtime |
   Selection reasons:
      - By constraint: dependency was locked to version '5.10.3'
      - By ancestor

org.junit.jupiter:junit-jupiter-engine:{strictly 5.10.3} -> 5.10.3
\--- project :jpa
     \--- project :jpa (*)

org.junit.jupiter:junit-jupiter-engine:5.10.3
+--- org.junit:junit-bom:5.10.3
|    +--- project :jpa (requested org.junit:junit-bom:5.+)
|    |    \--- project :jpa (*)
|    +--- org.junit.jupiter:junit-jupiter-params:5.10.3
|    |    +--- project :jpa (requested org.junit.jupiter:junit-jupiter-params) (*)
|    |    +--- org.springframework.boot:spring-boot-dependencies:3.3.2
|    |    |    +--- project :jpa (requested org.springframework.boot:spring-boot-dependencies:3.+) (*)
|    |    |    +--- project :model (requested org.springframework.boot:spring-boot-dependencies:3.+)
|    |    |    |    \--- project :jpa (*)
|    |    |    \--- project :test-app (requested org.springframework.boot:spring-boot-dependencies:3.+)
|    |    |         \--- project :jpa (*)
|    |    \--- org.junit:junit-bom:5.10.3 (*)
|    +--- org.junit.jupiter:junit-jupiter-engine:5.10.3 (*)
|    +--- org.junit.jupiter:junit-jupiter-api:5.10.3
|    |    +--- project :jpa (requested org.junit.jupiter:junit-jupiter-api) (*)
|    |    +--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)
|    |    +--- org.junit.jupiter:junit-jupiter-params:5.10.3 (*)
|    |    +--- org.junit.jupiter:junit-jupiter-engine:5.10.3 (*)
|    |    \--- org.junit:junit-bom:5.10.3 (*)
|    +--- org.junit.platform:junit-platform-launcher:1.10.3
|    |    +--- project :jpa (requested org.junit.platform:junit-platform-launcher) (*)
|    |    +--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)
|    |    \--- org.junit:junit-bom:5.10.3 (*)
|    +--- org.junit.platform:junit-platform-engine:1.10.3
|    |    +--- project :jpa (requested org.junit.platform:junit-platform-engine:{strictly 1.10.3}) (*)
|    |    +--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)
|    |    +--- org.junit.jupiter:junit-jupiter-engine:5.10.3 (*)
|    |    +--- org.junit.platform:junit-platform-launcher:1.10.3 (*)
|    |    \--- org.junit:junit-bom:5.10.3 (*)
|    \--- org.junit.platform:junit-platform-commons:1.10.3
|         +--- project :jpa (requested org.junit.platform:junit-platform-commons:{strictly 1.10.3}) (*)
|         +--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)
|         +--- org.junit.jupiter:junit-jupiter-api:5.10.3 (*)
|         +--- org.junit.platform:junit-platform-engine:1.10.3 (*)
|         \--- org.junit:junit-bom:5.10.3 (*)
\--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)

org.junit.jupiter:junit-jupiter-engine -> 5.10.3
\--- project :jpa
     \--- project :jpa (*)

org.junit.jupiter:junit-jupiter-params:5.10.3
  Variant runtimeElements:
    | Attribute Name                     | Provided     | Requested    |
    |------------------------------------|--------------|--------------|
    | org.gradle.status                  | release      |              |
    | org.jetbrains.kotlin.platform.type | jvm          |              |
    | org.gradle.category                | library      | library      |
    | org.gradle.dependency.bundling     | external     | external     |
    | org.gradle.jvm.environment         | standard-jvm | standard-jvm |
    | org.gradle.jvm.version             | 8            | 21           |
    | org.gradle.libraryelements         | jar          | jar          |
    | org.gradle.usage                   | java-runtime | java-runtime |
   Selection reasons:
      - By constraint: dependency was locked to version '5.10.3'
      - By ancestor

org.junit.jupiter:junit-jupiter-params:{strictly 5.10.3} -> 5.10.3
\--- project :jpa
     \--- project :jpa (*)

org.junit.jupiter:junit-jupiter-params:5.10.3
+--- org.junit:junit-bom:5.10.3
|    +--- project :jpa (requested org.junit:junit-bom:5.+)
|    |    \--- project :jpa (*)
|    +--- org.junit.jupiter:junit-jupiter-params:5.10.3 (*)
|    +--- org.junit.jupiter:junit-jupiter-engine:5.10.3
|    |    +--- project :jpa (requested org.junit.jupiter:junit-jupiter-engine) (*)
|    |    +--- org.springframework.boot:spring-boot-dependencies:3.3.2
|    |    |    +--- project :jpa (requested org.springframework.boot:spring-boot-dependencies:3.+) (*)
|    |    |    +--- project :model (requested org.springframework.boot:spring-boot-dependencies:3.+)
|    |    |    |    \--- project :jpa (*)
|    |    |    \--- project :test-app (requested org.springframework.boot:spring-boot-dependencies:3.+)
|    |    |         \--- project :jpa (*)
|    |    \--- org.junit:junit-bom:5.10.3 (*)
|    +--- org.junit.jupiter:junit-jupiter-api:5.10.3
|    |    +--- project :jpa (requested org.junit.jupiter:junit-jupiter-api) (*)
|    |    +--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)
|    |    +--- org.junit.jupiter:junit-jupiter-params:5.10.3 (*)
|    |    +--- org.junit.jupiter:junit-jupiter-engine:5.10.3 (*)
|    |    \--- org.junit:junit-bom:5.10.3 (*)
|    +--- org.junit.platform:junit-platform-launcher:1.10.3
|    |    +--- project :jpa (requested org.junit.platform:junit-platform-launcher) (*)
|    |    +--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)
|    |    \--- org.junit:junit-bom:5.10.3 (*)
|    +--- org.junit.platform:junit-platform-engine:1.10.3
|    |    +--- project :jpa (requested org.junit.platform:junit-platform-engine:{strictly 1.10.3}) (*)
|    |    +--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)
|    |    +--- org.junit.jupiter:junit-jupiter-engine:5.10.3 (*)
|    |    +--- org.junit.platform:junit-platform-launcher:1.10.3 (*)
|    |    \--- org.junit:junit-bom:5.10.3 (*)
|    \--- org.junit.platform:junit-platform-commons:1.10.3
|         +--- project :jpa (requested org.junit.platform:junit-platform-commons:{strictly 1.10.3}) (*)
|         +--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)
|         +--- org.junit.jupiter:junit-jupiter-api:5.10.3 (*)
|         +--- org.junit.platform:junit-platform-engine:1.10.3 (*)
|         \--- org.junit:junit-bom:5.10.3 (*)
\--- org.springframework.boot:spring-boot-dependencies:3.3.2 (*)

org.junit.jupiter:junit-jupiter-params -> 5.10.3
\--- project :jpa
     \--- project :jpa (*)

(*) - Indicates repeated occurrences of a transitive dependency subtree. Gradle expands transitive dependency subtrees only once per project; repeat occurrences only display the root of the subtree, followed by this annotation.

A web-based, searchable dependency report is available by adding the --scan option.

BUILD SUCCESSFUL in 772ms
1 actionable task: 1 executed
Configuration cache entry reused.
anyways, I'm gonna get back to working on my JPMS-ifying of my test suites
v
Doesn't matter, the
junit-jupiter
artifact is just a meta package anyway.
It has a phyiscal jar, but that is only containing a license file and imho is more a build bug / packaging bug
It's just for easily depending on multiple modules
And actually now I see it also includes
-params
, so if you have
junit-jupiter
-params
is already included
c
right, it's basically a starter
1
v
So also when you use
useJunitJupiter