下载wiremock
启动
java -jar wiremock-jre8-standalone-2.33.1.jar --port 8888
创建工程
添加依赖
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.27.0</version>
</dependency>
运行代码
/**
* @Author
* @Date
* @Description:
*/
public class WireMockClient {
public static void main(String[] args) throws IOException {
configureFor(8888);
removeAllMappings();
mock("/test", "test.json");
}
public static void mock(String url, String file) throws IOException {
ClassPathResource resource = new ClassPathResource("wiremock/" + file);
String result = FileUtils.readFileToString(resource.getFile());
stubFor(get(urlPathEqualTo(url)).willReturn(aResponse().withBody(result).withStatus(200)));
}
}
访问