【发布时间】:2020-02-05 22:03:39
【问题描述】:
我正在尝试让 mockMvc 调用与 wiremock 一起运行。但是代码中下面的 mockMvc 调用不断抛出 404 而不是预期的 200 HTTP 状态代码。
我知道wiremock正在运行..我可以在wiremock运行时通过浏览器执行http://localhost:8070/lala。
有人可以建议吗?
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestApp.class)
@AutoConfigureMockMvc
public class MyControllerTest {
@Inject
public MockMvc mockMvc;
@ClassRule
public static final WireMockClassRule wireMockRule = new WireMockClassRule(8070);
@Rule
public WireMockClassRule instanceRule = wireMockRule;
public ResponseDefinitionBuilder responseBuilder(HttpStatus httpStatus) {
return aResponse()
.withStatus(httpStatus.value());
}
@Test
public void testOne() throws Exception {
stubFor(WireMock
.request(HttpMethod.GET.name(), urlPathMatching("/lala"))
.willReturn(responseBuilder(HttpStatus.OK)));
Thread.sleep(1000000);
mockMvc.perform(MockMvcRequestBuilders.request(HttpMethod.GET, "/lala")) .andExpect(status().isOk());
}
}
【问题讨论】:
-
我已经更新了帖子中的代码以显示完整的测试类。
标签: java spring spring-boot wiremock