I have a test for a Feign client and I would like to set up a test slice, like @WebMvcTest
, @DataJpaTest
, etc.
For example, the following test uses @SpringBootTest
and it loads all the application context:
@SpringBootTest
@AutoConfigureWireMock(port = 0)
class AgePredictorFeignClientTest {
@Autowired
private AgePredictorFeignClient agePredictorFeignClient;
@Test
void getAge() {
stubFor(get(urlEqualTo("/age-api?name=Henrique"))
.willReturn(aResponse().withBodyFile("25_years_old.json")
.withHeader("Content-Type", "application/json")));
Integer age = agePredictorFeignClient.getAge("Henrique").getAge();
assertThat(age).isEqualTo(25);
verify(getRequestedFor(urlEqualTo("/age-api?name=Henrique")));
}
}
How could I change this test to load only the context related to Spring Cloud OpenFeign?
The source code for the application with this test is available at https://github.com/henriquels25/openfeign-tests-sample.