Skip to content

Latest commit

 

History

History
53 lines (43 loc) · 1.88 KB

README.md

File metadata and controls

53 lines (43 loc) · 1.88 KB

Spring Mock Feign Clients

Build Status Maven Central Coverage Status

Simple library for testing Feign Clients using MockMvc or TestRestTemplate instances.

Useful for when you want to test your Spring REST Controllers and associated Feign Client for compatibility.

Usage

See the src/test/java folder for a fully fledged example, but in short:

  1. Include this library as a test dependency
  2. Add Feign global configuration (to use MockMvc or TestRestTemplate based upon your preference)
    • MockMvc should execute quicker as TestRestTemplate requires a full server stack

MockMvc Usage

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
@EnableFeignClients(defaultConfiguration = MockMvcFeignConfiguration.class)
public class MockMvcFeignClientTest {
    // ...
}

public class MockMvcFeignConfiguration {
    @Bean
    Client feignClient() {
        return new MockMvcFeignClient();
    }
}

TestRestTemplate Usage

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
@EnableFeignClients(defaultConfiguration = TestRestTemplateFeignConfiguration.class)
public class RestTemplateFeignClientTest {
    // ...
}

public class TestRestTemplateFeignConfiguration {
    @Bean
    Client feignClient() {
        return new RestTemplateFeignClient();
    }
}