You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
No problems on producer side. Base test class annotated with @WebMvcTest, so only Web Layer getting configured and has same state as for production deployment. Services mocked, Web works, tests passed, stubs published
Issue comes on consumer side.
We are using Feign as client. So Preferable solution is to create test, inject FeignClient with same configuration, as for production deployment and perform http requests using using Feign abstraction.
Example from documentation:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.NONE)
@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:6565"},
stubsMode = StubRunnerProperties.StubsMode.LOCAL)
public class LoanApplicationServiceTests
This will work, but in services with complex configuration it is difficult to create such configuration (@SpringBootTest).
All properties must be set, production only beans must be mocked, etc. More over - there is no need for Feign tests to create all service, configuration and controller beans.
So existent of special annotation for Feign Client Layer Test (@FeignTest) will helps a lot and sounds reasonable.
But to create this annotation deep knowledge of all Feign related spring auto configurations required (web converters, ribbon, eureka, jackson, etc.)
It would be great, if you will able to implement this annotation.
Thanks in advance,
Yesman Maxim.
Reacted by ikatlinsky, Ruslan Papko, philkevich, Yuriy Sych , Swyatoslaw, Dmitry Skuratovich, Vadim Yurchak, ColourOfMagic, MeatAss, Andrey Redkovskiy and 26 more
Reacted by Viktor, JustRandomName and Roman Sanchenko
Hello, thanks for proposing this. @SpringBootTest provides the possibility to pass the exact configuration to use in the test and is very flexible. The feature you describe is a possible enhancement, but we must first verify how much interest in such a feature there is in the community. Marking as "waiting for votes".
Hey @OlgaMaciaszek. I came across this issue and wanted to share something I did recently at work (and used with success): https://github.com/poznachowski/feigntest
This is what we would call a Feign slice test: Only things related to Feign (and Wiremock) are bootstrapped. It follows the same code structure as other Spring Boot slice tests. However, it is tailored a bit for my company's need: we always use @FeignClienturl parameter, which is then substituted by the url of Wiremock.
If you find this (or something with this shape) worth adding - I'd be glad to contribute (preceded with some guidance).
Reacted by Maxim Yesman, Nazeem, jaco0646, Mikalai Alimenkou, Sławomir Szczurek and s-kocher
@OlgaMaciaszek trying to draw a little more attention :) I can try and submit a MR request already, but still got some concerns about how to do it right.
My solution, for instance, is based on additional dependency of spring-cloud-contract-wiremock. I'd assume it should rather be an opt-in solution, that can be recommended in the docs.
Hi @ryanjbaxter, this is the most voted open issue in the project, so I'd like to contribute it if you're open to it. Here is a sketch, modelled on Spring Boot's @RestClientTest:
A @FeignClientTest slice, with an optional clients attribute. It bootstraps the listed @FeignClient interfaces (or all of them when none are listed), the Feign auto-configuration and the HTTP message converters, and leaves out the other components of the application.
It would not pick a stub server. Tests point a client at WireMock, MockWebServer or a Spring Cloud Contract stub with the usual spring.cloud.openfeign.client.config.<name>.url property, and the docs would show a WireMock example.
An @AutoConfigureFeign annotation that adds the same auto-configuration to another slice or to a @SpringBootTest.
It could ship as a small spring-cloud-openfeign-test module, or as an optional test support package in spring-cloud-openfeign-core if you'd rather not add a module. I'm happy to adjust the shape before starting.
Thanks @ryanjbaxter. The slice would not depend on Spring Cloud Contract. It would only bootstrap the @FeignClient interfaces and the Feign auto-configuration, and the test would point the client at any stub server through spring.cloud.openfeign.client.config.<name>.url. That could be WireMock or MockWebServer, the same way @RestClientTest works with MockRestServiceServer. I only mentioned Contract stubs as one of the options.
If you still do not think it is worth adding, I am happy to leave it.
You can, and that works today with a @SpringBootTest. The slice would add only what @RestClientTest adds over a @SpringBootTest with MockRestServiceServer: the test context starts with just the Feign clients, the Feign auto-configuration and the message converters. So a client test does not need the database, broker or security setup of the rest of the application.
Without it, a test narrows the context by hand with @ImportAutoConfiguration, and the list to import changes between Boot versions. In Boot 4, for example, the message converter and Jackson auto-configurations moved to new modules. The slice would keep that list in one place.
That is the whole benefit, so if you do not think it is worth a test module, I am fine with leaving it.
I opened #1449 with the slice, so you can see what it would look like. It is a separate spring-cloud-openfeign-test module with @FeignClientTest and @AutoConfigureFeign, and the description explains the design choices. As you said, it can wait for the next major.
Activity
OlgaMaciaszek commentedon Nov 12, 2020
Hello, thanks for proposing this.
@SpringBootTestprovides the possibility to pass the exact configuration to use in the test and is very flexible. The feature you describe is a possible enhancement, but we must first verify how much interest in such a feature there is in the community. Marking as "waiting for votes".yesmanmx commentedon Nov 12, 2020
Thank for reply
poznachowski commentedon Nov 24, 2021
Hey @OlgaMaciaszek. I came across this issue and wanted to share something I did recently at work (and used with success):
https://github.com/poznachowski/feigntest
This is what we would call a Feign slice test: Only things related to Feign (and Wiremock) are bootstrapped. It follows the same code structure as other Spring Boot slice tests. However, it is tailored a bit for my company's need: we always use
@FeignClienturlparameter, which is then substituted by the url of Wiremock.If you find this (or something with this shape) worth adding - I'd be glad to contribute (preceded with some guidance).
poznachowski commentedon Dec 22, 2021
@OlgaMaciaszek trying to draw a little more attention :) I can try and submit a MR request already, but still got some concerns about how to do it right.
My solution, for instance, is based on additional dependency of
spring-cloud-contract-wiremock. I'd assume it should rather be an opt-in solution, that can be recommended in the docs.sharanggupta commentedon Oct 15, 2026
Hi @ryanjbaxter, this is the most voted open issue in the project, so I'd like to contribute it if you're open to it. Here is a sketch, modelled on Spring Boot's
@RestClientTest:@FeignClientTestslice, with an optionalclientsattribute. It bootstraps the listed@FeignClientinterfaces (or all of them when none are listed), the Feign auto-configuration and the HTTP message converters, and leaves out the other components of the application.spring.cloud.openfeign.client.config.<name>.urlproperty, and the docs would show a WireMock example.@AutoConfigureFeignannotation that adds the same auto-configuration to another slice or to a@SpringBootTest.It could ship as a small
spring-cloud-openfeign-testmodule, or as an optional test support package inspring-cloud-openfeign-coreif you'd rather not add a module. I'm happy to adjust the shape before starting.ryanjbaxter commentedon Oct 15, 2026
Spring Cloud Contract is no longer part of Spring Cloud. It was moved to stubborn.sh, so I am not sure this is really useful any longer
sharanggupta commentedon Oct 15, 2026
Thanks @ryanjbaxter. The slice would not depend on Spring Cloud Contract. It would only bootstrap the
@FeignClientinterfaces and the Feign auto-configuration, and the test would point the client at any stub server throughspring.cloud.openfeign.client.config.<name>.url. That could be WireMock or MockWebServer, the same way@RestClientTestworks withMockRestServiceServer. I only mentioned Contract stubs as one of the options.If you still do not think it is worth adding, I am happy to leave it.
ryanjbaxter commentedon Oct 15, 2026
But why can't you just point the feign client at that mock server using configuration?
sharanggupta commentedon Oct 15, 2026
You can, and that works today with a
@SpringBootTest. The slice would add only what@RestClientTestadds over a@SpringBootTestwithMockRestServiceServer: the test context starts with just the Feign clients, the Feign auto-configuration and the message converters. So a client test does not need the database, broker or security setup of the rest of the application.Without it, a test narrows the context by hand with
@ImportAutoConfiguration, and the list to import changes between Boot versions. In Boot 4, for example, the message converter and Jackson auto-configurations moved to new modules. The slice would keep that list in one place.That is the whole benefit, so if you do not think it is worth a test module, I am fine with leaving it.
ryanjbaxter commentedon Oct 15, 2026
I guess we can see what the PR would look like for this. But IMO it would be something we would hold off on merging until the next major comes around.
sharanggupta commentedon Oct 15, 2026
Thanks @ryanjbaxter, that makes sense. I will put the PR together so you can see the shape, and holding it for the next major is fine.
sharanggupta commentedon Oct 15, 2026
I opened #1449 with the slice, so you can see what it would look like. It is a separate
spring-cloud-openfeign-testmodule with@FeignClientTestand@AutoConfigureFeign, and the description explains the design choices. As you said, it can wait for the next major.