spring-cloud / spring-cloud/spring-cloud-openfeign

Add @FeignTest annotation for Feign Layer

Open
#427 4 comments 39 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement waiting for votes
Dominant language
Java
Stars
1.3k
Forks
838
Avg merge
2d 11h
Merged PRs (30d)
13

Description

Hello!
I started to integrate Spring Cloud Contract into existing project.

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the existing @WebMvcTest and @SpringBootTest examples with the @AutoConfigureStubRunner consumer setup described in the issue. Define what @FeignTest must configure for Feign clients and what production beans it must exclude, then verify that a consumer test can issue requests through the Feign abstraction without starting the full application.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.