Skip to content
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

Spock Spring module does not work with Spring Test 6 #1539

Closed
Poundex opened this issue Oct 29, 2022 · 6 comments · Fixed by #1541
Closed

Spock Spring module does not work with Spring Test 6 #1539

Poundex opened this issue Oct 29, 2022 · 6 comments · Fixed by #1541
Labels

Comments

@Poundex
Copy link

Poundex commented Oct 29, 2022

Describe the bug

When using Spring Test 6 (used by Spring 6/Boot 3) then the Spock Spring module does not detect the Spring tests. The tests are still picked up and an attempt to execute them is made, but the Spring Application Context is never started.

The issue seems to be caused by the class org.springframework.test.util.MetaAnnotationUtils which was deprecated in 5.3 being removed in 6. It looks like Spock used this utility class to discover the @BootstrapWith meta-annotation on the @SpringBootTest annotation.

There are separate checks for @ContextHierarchy and @ContextConfiguration, so if a Spec is using these directly then the Application Context starts as expected.

Workaround
Add an empty @ContextConfiguration annotation to the Spec.

To Reproduce

@SpringBootTest(classes = [DemoApplication, JustATestSpec])
class JustATestSpec extends Specification implements ApplicationListener<ApplicationReadyEvent> {
	
	static boolean contextSeenStarting = false
	
	@Override
	void onApplicationEvent(ApplicationReadyEvent event) {
		contextSeenStarting = true
	}

	void "Starts Application Context"() {
		expect:
		contextSeenStarting
	}
}

Expected behavior

Application context starts

Actual behavior

Application context doesn't start

Java version

All

Buildtool version

All

What operating system are you using

Linux

Dependencies

?

Additional context

No response

@Poundex Poundex added the bug label Oct 29, 2022
@sbhuju61
Copy link

This workaround helped me. Thanks.

leonard84 added a commit to leonard84/spock that referenced this issue Nov 9, 2022
by using its replacement TestContextAnnotationUtils.

fixes spockframework#1539
leonard84 added a commit to leonard84/spock that referenced this issue Nov 30, 2022
by using its replacement TestContextAnnotationUtils.

fixes spockframework#1539
leonard84 added a commit that referenced this issue Nov 30, 2022
* Add SpringBoot 3 integration test
* Fix issue with removed MetaAnnotationUtils by using its replacement TestContextAnnotationUtils.
* Raise required JDK version for the gradle build to 17 to accommodate Spring Boot 3.

fixes #1539
murygin pushed a commit to SerNet/verinice-veo-reporting that referenced this issue Dec 1, 2022
dawids21 added a commit to dawids21/CoBudget-backend that referenced this issue Dec 10, 2022
@winne42
Copy link

winne42 commented Feb 13, 2023

@leonard84 I assume that many Spock users are desperately waiting for your fix. Do you have any idea about when a new Spock version including your fix will be released?

@sbhuju61
Copy link

@winne42 The fix has already been released. I was able to successfully use it few weeks ago.
I used 2.4-M1-groovy-4.0. I believe other version also have the fix.

https://mvnrepository.com/artifact/org.spockframework/spock-spring/2.4-M1-groovy-4.0

@winne42
Copy link

winne42 commented Feb 14, 2023

@sbhuju61 but is the "M1" release supposed to be stable? Sounds like a "milestone" to me?

@sbhuju61
Copy link

sbhuju61 commented Feb 16, 2023

@sbhuju61 but is the "M1" release supposed to be stable? Sounds like a "milestone" to me?

@winne42 It is a milestone and not as stable as final release. I have been using it since mid December of 2022 and have not run into any issues yet.

@nniesen
Copy link

nniesen commented Jun 16, 2023

This has been stuck in a Milestone Release for 6 months. Any chance it can be released or backport to 2.3. Currently, the only options appear to be not upgrading to Boot 3.x or having to depend on a Milestone dependency.

KHyeon9 pushed a commit to KHyeon9/SearchPharmacy that referenced this issue Jun 12, 2024
스프링6에서 작동이 안되므로 2.4-M1 이상 버전을 사용해야함
참조
- spockframework/spock#1539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants