Open lmouline opened 1 year ago
And this works with prior Spring Boot versions?
IIRC @WebMvcTest([DummyController.class])
restricts loading of beans, so I'd assume that the @EnableFeignClients
is not picked up and you need to explicitly add it to the context.
As you can see by the error message:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.openfeign.FeignClientFactory' available
This means that Spock did correctly invoke the Spring testing infrastructure.
It might be related to the old thread: https://github.com/spring-projects/spring-boot/issues/7270#issuecomment-332525848.
I've bumped into that case recently. The weird thing is, it worked fine with Spring Boot 2 and Spock 2.3. However, I clearly see that in SB2 the Feign client (GoogleClient
in your case) is not instantiated by default (when I try to inject it explicitly into my test, I have No qualifying bean of type 'org.springframework.cloud.openfeign.FeignContext' available
). After the migration to SB3 - it is instantiated automatically with the same @WebMvcTest
configuration which generates the problem.
@lmouline Could you write one test with JUnit Jupiter and the aforementioned @WebMvcTest
configuration to check if it still fails? If yes, I would be looking for the changes in Spring Boot 3 (or some underlying Spring components) as a reason.
@leonard84
And this works with prior Spring Boot versions?
Yep it does :)
From the demo project, using the following dependencies (without changing the code) makes it pass:
plugins {
id("org.springframework.boot") version "2.7.8"
}
extra["springCloudVersion"] = "2021.0.5"
dependencies {
testImplementation(platform("org.spockframework:spock-bom:2.3-groovy-4.0"))
}
@szpak
Could you write one test with JUnit Jupiter and the aforementioned @WebMvcTest configuration to check if it still fails?
The test with Junit works :( Here a new version of a demo with both the Spock test and the JUnit one. They are strictly identical. But you can see that only the JUnit one works :/ demo.zip
Honestly, not sure what the cause is, as Spock is not really involved in that part. It just instantiates Spring's TestContextManager
with the Specification and calls it's lifecycle methods at the correct time. Everything else should be handled by Spring (Boot) internals.
Describe the bug
When migration Spring Boot to version 3 and Spock framework to version 2.4-M1 with OpenFeign client(s), tests with the
WebMvcTest
annotation fail to properly load the context.Please note that the tests with
@SpringBootTest
are executed successfully.Seems that the issue also happens for tests with the
@DataMongoTest
annotation.To Reproduce
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.apache.groovy:groovy:4.0.7") testImplementation(platform("org.spockframework:spock-bom:2.4-M1-groovy-4.0")) testImplementation("org.spockframework:spock-core") testImplementation("org.spockframework:spock-spring")
Create a WebMvcTest that test the controller
Minimal example with a failing test: demo.zip
Expected behavior
The test should pass
Actual behavior
The test fails with the following cause:
(Note that the test with the
@SpringBootTest
annotation passes :))Java version
17
Buildtool version
Gradle 7.6
What operating system are you using
Mac
Dependencies
Root project 'demo'
A web-based, searchable dependency report is available by adding the --scan option.
Additional context
No response