码迷,mamicode.com
首页 > 其他好文 > 详细

WireMock提供Restful接口数据

时间:2018-06-17 16:03:55      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:Stub   org   ring   googl   ack   generate   pac   void   ati   

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接口数据

标签:Stub   org   ring   googl   ack   generate   pac   void   ati   

原文地址:https://www.cnblogs.com/kibana/p/9192976.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!