How to get wiremock running before the spring boot application status up?
you might create static instance of WireMockServer in your test. Here is a code sample:
@RunWith(SpringRunner.class)
@SpringBootTest
public class YourApplicationTests {
static WireMockServer mockHttpServer = new WireMockServer(10000); // endpoint port here
@BeforeClass
public static void setup() throws Exception {
mockHttpServer.stubFor(get(urlPathMatching("/")).willReturn(aResponse().withBody("test").withStatus(200)));
mockHttpServer.start();
}
@AfterClass
public static void teardown() throws Exception {
mockHttpServer.stop();
}
@Test
public void someTest() throws Exception {
// your test code here
}
}
The Spring Boot team have built a WireMock integration. Might be worth checking it out rather than rolling your own: http://cloud.spring.io/spring-cloud-static/spring-cloud-contract/1.1.2.RELEASE/#_spring_cloud_contract_wiremock