WireMock提供Restful接口数据
Posted kibana
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WireMock提供Restful接口数据相关的知识,希望对你有一定的参考价值。
1、去官网下载并启动:
2、引入Pom依赖:
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.1-jre</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.5</version>
</dependency>
3、编写客户端设置请求与响应:
package wiremock;
import com.github.tomakehurst.wiremock.client.WireMock;
public class WireMockClient {
public static void main(String[] args) {
// TODO Auto-generated method stub
WireMock.configureFor(8090);
WireMock.removeAllMappings();
WireMock.stubFor(
WireMock.get(WireMock.urlPathEqualTo("/order/1")).
willReturn(WireMock.aResponse().
withBody("{"id":1,"name":"cqu2010"}").withStatus(200))); //伪造测试桩
}
}
4、测试:
以上是关于WireMock提供Restful接口数据的主要内容,如果未能解决你的问题,请参考以下文章