Giter VIP home page Giter VIP logo

dubbo-easy-mock's Introduction

Build Status

这个框架的作用

在自动测试中,针对dubbo接口进行mock的框架

原理

利用dubbo的扩展点自动包装,通过EasyMockClusterWrapper将原本的rpc请求改写为http请求转发到mock服务器返回我们对应mock结果

使用

1. 添加依赖

mvn clean package install (deploy) -Dmaven.test.skip=true 编译安装依赖到本地/远程仓库

<dependency>
    <groupId>com.cmt</groupId>
    <artifactId>dubbo-easy-mock</artifactId>
    <version>1.1.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo</artifactId>
        </exclusion>
    </exclusions>
</dependency>

2. classpath增加mock.properties

## 是否启用mock
easymock.enable=true
## mock服务器地址
easymock.server.url=https://easy-mock.com/mock/5c77afd53ecfbb573cba5df8/test
## 接口级别mock开关 
easymock.tests.HelloService=true
## 方法级别mock开关,优先级大于接口级别
easymock.tests.HelloService.hello=true

3. mock服务-请求约束

本框架对mock服务器不做限制,但是发送的mock请求需要遵循以下约束

  1. 请求类型为GET,请求path为/接口全限定名/方法名
  2. 返回格式为json
    对于基本类型,因为json仅支持对象和数组两种结构,所以需要用以下格式嵌套一层
{
    "data":xxx
}

对于其他类型,比如对象,Map,Collection等其他类型,与FastJson生成的一致即可

mock服务器推荐 easy-mock或者mockserver这两个项目

更新

2020-03-12 - 兼容apache和alibaba版本的dubbo

示例工程

dubbo-easy-mock-demo

相关文章

针对Dubbo接口Mock的解决方案

dubbo-easy-mock's People

Contributors

shengchaojie avatar whitebookman1994 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.