Skip to content

Commit 55e800f

Browse files
committed
Add junit6-integration test project
This shall ensure the execution with JUnit 6 is possible.
1 parent aaf5b4d commit 55e800f

File tree

9 files changed

+79
-6
lines changed

9 files changed

+79
-6
lines changed

.github/renovate.json5

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
matchCurrentValue: "/^4\\./",
2121
allowedVersions: "(,5.0)"
2222
},
23+
{
24+
matchPackageNames: ["/^org.junit:/"],
25+
matchCurrentValue: "/^5\\./",
26+
allowedVersions: "(,6.0)"
27+
},
28+
{
29+
matchPackageNames: ["/^org.junit:/"],
30+
matchCurrentValue: "/^6\\./",
31+
allowedVersions: "(,7.0)"
32+
},
2333
{
2434
matchPackageNames: ["/^org.mockito:/"],
2535
matchCurrentValue: "/^4\\./",

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ subprojects {
157157
dependencies {
158158
api platform(projects.spockBom)
159159
implementation(project.name == "spock-gradle" ? [] : groovylibs.groovy)
160-
testImplementation(platform(libs.junit.bom))
160+
if (project.name != "junit6-integration") {
161+
testImplementation(platform(libs.junit5.bom))
162+
}
161163
testImplementation(libs.junit.platform.launcher)
162164
}
163165

gradle/libs.versions.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ groovy2 = '2.5.23'
44
groovy3 = '3.0.25'
55
groovy4 = '4.0.29'
66
jacoco = '0.8.14'
7-
junit = '5.14.0'
7+
junit5 = '5.14.0'
8+
junit6 = '6.0.0'
89
# The VersionRange used by OSGi to check compatibility with JUnit Platform.
910
junitPlatformVersionRange = "[1.12,7)"
1011
asm = '9.9'
@@ -31,7 +32,8 @@ mockito5 = { module = "org.mockito:mockito-core", version.ref = "mockito5" }
3132
objenesis = "org.objenesis:objenesis:3.4"
3233
# This needs a classifier, but it has to be specified on the usage end https://melix.github.io/blog/2021/03/version-catalogs-faq.html#_why_can_t_i_use_excludes_or_classifiers
3334
jacoco-agent = { module = "org.jacoco:org.jacoco.agent", version.ref = "jacoco" }
34-
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
35+
junit5-bom = { module = "org.junit:junit-bom", version.ref = "junit5" }
36+
junit6-bom = { module = "org.junit:junit-bom", version.ref = "junit6" }
3537
# to omit the version we have to use this syntax, the version is managed by the junit-bom
3638
junit-jupiter.module = "org.junit.jupiter:junit-jupiter"
3739
junit-platform-console.module = "org.junit.platform:junit-platform-console"

settings.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ if (javaVersion <= 17) {
119119
include "spock-spring:spring3-test"
120120
include "spock-spring:spring5-test"
121121

122+
123+
if (javaVersion >= 17) {
124+
//JUnit 6 only works for Java 17 and newer
125+
include "spock-specs:junit6-integration"
126+
}
127+
122128
rootProject.name = "spock"
123129
nameBuildScriptsAfterProjectNames(rootProject.children)
124130

spock-core/core.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ configurations {
2222

2323
dependencies {
2424
api groovylibs.groovy // easiest way to add Groovy dependency to POM
25-
api platform(libs.junit.bom)
25+
api platform(libs.junit5.bom)
2626
api 'org.junit.platform:junit-platform-engine'
2727
api libs.hamcrest
2828
if (variant == 2.5) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ext.displayName = "Spock Framework - Integration Specs for JUnit 6"
2+
3+
description = "Integration Specs for JUnit 6 as runtime platform"
4+
5+
6+
dependencies {
7+
testImplementation(projects.spockCore)
8+
testImplementation(platform(libs.junit6.bom))
9+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.spockframework
17+
18+
import org.junit.platform.commons.support.ReflectionSupport
19+
import org.junit.platform.engine.TestEngine
20+
import org.junit.platform.launcher.Launcher
21+
import spock.lang.Specification
22+
23+
/**
24+
* The specification shall verify that Spock can run with JUnit 6 as a runtime platform.
25+
*/
26+
class JUnit6IntegrationSpec extends Specification {
27+
28+
def "Simple JUnit 6 test"() {
29+
expect:
30+
true
31+
}
32+
33+
def "Verify JUnit version of JUnit classes"() {
34+
expect:
35+
cls.package.implementationVersion.startsWith("6.")
36+
37+
where:
38+
cls << [
39+
ReflectionSupport.class,//junit-platform-commons
40+
Launcher.class, //junit-platform-launcher
41+
TestEngine.class //junit-platform-engine
42+
]
43+
}
44+
}

spock-spring/boot2-test/boot2-test.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencyManagement {
3232
}
3333

3434
// Spring dependency management downgrades the jupiter version to 5.7.2 otherwise
35-
ext['junit-jupiter.version'] = libs.versions.junit.get()
35+
ext['junit-jupiter.version'] = libs.versions.junit5.get()
3636

3737
dependencies {
3838
implementation "org.springframework.boot:spring-boot-starter-data-jpa"

spock-spring/boot3-test/boot3-test.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020
}
2121

2222
// Spring dependency management downgrades the jupiter version to 5.7.2 otherwise
23-
ext['junit-jupiter.version'] = libs.versions.junit.get()
23+
ext['junit-jupiter.version'] = libs.versions.junit5.get()
2424

2525
java {
2626
toolchain {

0 commit comments

Comments
 (0)