wireMock快速伪造restful服务
生活随笔
收集整理的這篇文章主要介紹了
wireMock快速伪造restful服务
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
wireMock快速偽造restful服務
官網地址:http://wiremock.org/
Jar下載:http://repo1.maven.org/maven2/com/github/tomakehurst/wiremock/1.57/wiremock-1.57-standalone.jar
下載wiremock jar工具
jar下載完畢后,啟動jar,
java -jar wiremock-1.57-standalone.jar –port 9999 --verbose?
配合springboot項目,能夠隨時更新mockservice
相關依賴:
<dependency><groupId>com.github.tomakehurst</groupId><artifactId>wiremock</artifactId></dependency>新建mock服務:
package com.nxz.wiremock;import com.github.tomakehurst.wiremock.client.WireMock; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.springframework.core.io.ClassPathResource;import java.io.IOException;/*** 啟動mockserver服務*/ public class MockServer {public static void main(String[] args) throws IOException {WireMock.configureFor(9999);//指定端口WireMock.removeAllMappings();//清空之前的配置//每調用一次mock方法,就代表提供了一個mockservice接口mock("/order/1", "01.txt");mock("/order/2", "02.txt");}private static void mock(String url, String file) throws IOException {//mock\\response\\+file 這里指定的是返回的json數據ClassPathResource resource = new ClassPathResource("mock\\response\\" + file);String content = StringUtils.join(FileUtils.readLines(resource.getFile(), "UTF-8").toArray());WireMock.stubFor(WireMock.get(WireMock.urlPathEqualTo(url)).willReturn(WireMock.aResponse().withBody(content).withStatus(200)));} }模擬返回數據:
{"aaa":1,"type":"a" }?
posted @ 2019-04-29 22:29 巡山小妖N 閱讀(...) 評論(...) 編輯 收藏總結
以上是生活随笔為你收集整理的wireMock快速伪造restful服务的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何异步的处理restful服务(基础)
- 下一篇: bootstrap学习(四)输入框、导航