Open kzwierzynski opened 5 years ago
Wiremock
testImplementation("org.springframework.cloud:spring-cloud-contract-wiremock")
@Configuration
class WireMockConfig {
@Bean
WireMockConfiguration wireMockConfiguration(@Value("${wiremock.server.port}") int port) {
return wireMockConfig()
.port(port)
.fileSource(new ClasspathFileSource("."))
.jettyHeaderBufferSize(32768)
.notifier(new Slf4jNotifier(true));
}
}
@RunWith(SpringRunner.class)
@ActiveProfiles("test")
@SpringBootTest(webEnvironment = RANDOM_PORT)
@AutoConfigureMockMvc
@AutoConfigureWireMock(port = DYNAMIC_PORT)
public abstract class IntegrationTest {
@Autowired
protected MockMvc mvc;
}
application-test.properties
app.web.client.some-third-party-service.host=http://localhost:${wiremock.server.port}
logging.WireMock=debug
public class SampleIntTest extends IntegrationTest {
@Test
public void shouldCheckEndpoint() throws Exception {
// given
MockHttpServletRequestBuilder request = MockMvcRequestBuilders
.get("/some-endpoint/2.1")
.param("param", "value")
.accept(APPLICATION_JSON_VALUE);
// when
ResultActions result = mvc.perform(request);
// then
result
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.filed", equalTo(false)));
}
}
Consider adding some tests to the project: -unit -integration -end to end (e2e) -performance -smoke Familiarize yourself with the notions connected with TDD and implement applicable/missing tests to the project.