【发布时间】:2020-11-19 13:10:33
【问题描述】:
我的wiremock 似乎不适用于自动配置。我在类路径中名为 stubs 的文件夹中有 json 文件,我在端口 8080 上运行了独立 jar。
@AutoConfigureWireMock(stubs="classpath:/stubs", port = 0)
public class TestResource {
@Autowired
private Service service;
@Test
public void contextLoads() throws Exception {
assertThat(this.service.go()).isEqualTo("Hello World!");
}
}
json 文件示例
{
"request" : {
"url" : "/api/users",
"method" : "GET",
"bodyPatterns" : [ {
"contains" : "some soap body"
}]
},
"response" : {
"status" : 200,
"body" : "Hello World",
"headers" : {
"X-Application-Context" : "application:-1",
"Content-Type" : "text/plain"
}
}
}
当我使用 GET -> localhost:8080/api/users/ 发起请求时,它与 json 文件不匹配。
提前致谢
【问题讨论】:
-
@AutoConfigureWireMock 的默认端口是 8080,这里尽量不要指定。
标签: java spring spring-boot stub wiremock