Skip to content

Commit 5399793

Browse files
committed
Reinstate Spock support
Closes gh-48513
1 parent 3011155 commit 5399793

File tree

7 files changed

+59
-2
lines changed

7 files changed

+59
-2
lines changed

core/spring-boot-test/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ dependencies {
5454
testImplementation("org.jetbrains.kotlin:kotlin-reflect")
5555
testImplementation("org.jetbrains.kotlin:kotlin-stdlib")
5656
testImplementation("org.slf4j:slf4j-api")
57+
testImplementation("org.spockframework:spock-core")
5758
testImplementation("org.springframework:spring-webmvc")
5859
testImplementation("org.testng:testng")
5960

60-
testRuntimeOnly("org.apache.groovy:groovy")
6161
testRuntimeOnly("org.aspectj:aspectjrt")
6262
testRuntimeOnly("org.aspectj:aspectjweaver")
6363
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")

core/spring-boot-test/src/main/java/org/springframework/boot/test/context/ImportsContextCustomizer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ static class ContextCustomizerKey {
228228
annotationFilters.add(AnnotationFilter.PLAIN);
229229
annotationFilters.add("kotlin.Metadata"::equals);
230230
annotationFilters.add(AnnotationFilter.packages("kotlin.annotation"));
231+
annotationFilters.add(AnnotationFilter.packages("org.spockframework", "spock"));
231232
annotationFilters.add(AnnotationFilter.packages("org.junit"));
232233
ANNOTATION_FILTERS = Collections.unmodifiableSet(annotationFilters);
233234
}

core/spring-boot-test/src/test/java/org/springframework/boot/test/context/ImportsContextCustomizerTests.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import org.junit.jupiter.api.Nested;
2626
import org.junit.jupiter.api.Tag;
2727
import org.junit.jupiter.api.Test;
28+
import org.spockframework.runtime.model.SpecMetadata;
29+
import spock.lang.Issue;
30+
import spock.lang.Stepwise;
2831

2932
import org.springframework.boot.context.annotation.DeterminableImports;
3033
import org.springframework.context.annotation.Configuration;
@@ -61,6 +64,18 @@ void customizersForTestClassesWithDifferentKotlinMetadataAreEqual() {
6164
.isEqualTo(new ImportsContextCustomizer(SecondKotlinAnnotatedTestClass.class));
6265
}
6366

67+
@Test
68+
void customizersForTestClassesWithDifferentSpockFrameworkAnnotationsAreEqual() {
69+
assertThat(new ImportsContextCustomizer(FirstSpockFrameworkAnnotatedTestClass.class))
70+
.isEqualTo(new ImportsContextCustomizer(SecondSpockFrameworkAnnotatedTestClass.class));
71+
}
72+
73+
@Test
74+
void customizersForTestClassesWithDifferentSpockLangAnnotationsAreEqual() {
75+
assertThat(new ImportsContextCustomizer(FirstSpockLangAnnotatedTestClass.class))
76+
.isEqualTo(new ImportsContextCustomizer(SecondSpockLangAnnotatedTestClass.class));
77+
}
78+
6479
@Test
6580
void customizersForTestClassesWithDifferentJUnitAnnotationsAreEqual() {
6681
assertThat(new ImportsContextCustomizer(FirstJUnitAnnotatedTestClass.class))
@@ -127,6 +142,30 @@ static class SecondKotlinAnnotatedTestClass {
127142

128143
}
129144

145+
@SpecMetadata(filename = "foo", line = 10)
146+
@Import(TestImportSelector.class)
147+
static class FirstSpockFrameworkAnnotatedTestClass {
148+
149+
}
150+
151+
@SpecMetadata(filename = "bar", line = 10)
152+
@Import(TestImportSelector.class)
153+
static class SecondSpockFrameworkAnnotatedTestClass {
154+
155+
}
156+
157+
@Stepwise
158+
@Import(TestImportSelector.class)
159+
static class FirstSpockLangAnnotatedTestClass {
160+
161+
}
162+
163+
@Issue("1234")
164+
@Import(TestImportSelector.class)
165+
static class SecondSpockLangAnnotatedTestClass {
166+
167+
}
168+
130169
@Nested
131170
@Import(TestImportSelector.class)
132171
static class FirstJUnitAnnotatedTestClass {

documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,8 @@
19011901
* xref:reference:testing/spring-boot-applications.adoc#testing.spring-boot-applications.mocking-beans[#boot-features-testing-spring-boot-applications-mocking-beans]
19021902
* xref:reference:testing/spring-boot-applications.adoc#testing.spring-boot-applications.mocking-beans[#features.testing.spring-boot-applications.mocking-beans]
19031903
* xref:reference:testing/spring-boot-applications.adoc#testing.spring-boot-applications.observations[#features.testing.spring-boot-applications.observations]
1904+
* xref:reference:testing/spring-boot-applications.adoc#testing.spring-boot-applications.spock[#boot-features-testing-spring-boot-applications-with-spock]
1905+
* xref:reference:testing/spring-boot-applications.adoc#testing.spring-boot-applications.spock[#features.testing.spring-boot-applications.spock]
19041906
* xref:reference:testing/spring-boot-applications.adoc#testing.spring-boot-applications.spring-graphql-tests[#features.testing.spring-boot-applications.spring-graphql-tests]
19051907
* xref:reference:testing/spring-boot-applications.adoc#testing.spring-boot-applications.spring-mvc-tests[#boot-features-testing-spring-boot-applications-testing-autoconfigured-mvc-tests]
19061908
* xref:reference:testing/spring-boot-applications.adoc#testing.spring-boot-applications.spring-mvc-tests[#features.testing.spring-boot-applications.spring-mvc-tests]

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,3 +925,11 @@ TIP: If this is not an option for you, you can create a javadoc:org.springframew
925925
Alternatively, you can specify a source for your test, which disables the behavior of finding a default one.
926926

927927

928+
929+
[[testing.spring-boot-applications.spock]]
930+
== Using Spock to Test Spring Boot Applications
931+
932+
Spock 2.4 or later can be used to test a Spring Boot application.
933+
To do so, add a dependency on a `-groovy-5.0` version of Spock's `spock-spring` module to your application's build.
934+
`spock-spring` integrates Spring's test framework into Spock.
935+
See https://spockframework.org/spock/docs/2.4/modules.html#spring-module[the documentation for Spock's Spring module] for further details.

module/spring-boot-health/src/test/java/org/springframework/boot/health/contributor/StatusTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void getDescriptionReturnsDescription() {
5959
void equalsAndHashCode() {
6060
Status one = new Status("spring", "boot");
6161
Status two = new Status("spring", "framework");
62-
Status three = new Status("another", "framework");
62+
Status three = new Status("spock", "framework");
6363
assertThat(one).isEqualTo(one).isEqualTo(two).isNotEqualTo(three);
6464
assertThat(one).hasSameHashCodeAs(two);
6565
}

platform/spring-boot-internal-dependencies/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ bom {
235235
]
236236
}
237237
}
238+
library("Spock Framework", "2.4-groovy-5.0") {
239+
group("org.spockframework") {
240+
modules = [
241+
"spock-core"
242+
]
243+
}
244+
}
238245
library("TestNG", "6.14.3") {
239246
group("org.testng") {
240247
modules = [

0 commit comments

Comments
 (0)