mock接口框架

╄→尐↘猪︶ㄣ 提交于 2019-12-03 01:27:25

mock测试

在接口测试过程中,对于某些不容易构造或者不容易获取的对象,我们常常会用一个虚拟的对象代替以便测试。

mock 使用

https://github.com/dreamhead/moco
One is API, which you can use in your unit test.
The other is that run Moco as standalone.
Currently, you put all your configuration in JSON file.

原理

根据配置,启动真正的HTTP服务(监听本地某端口)。发起请求满足一条件时,就会收到应答。
基于Netty的的网络应用框架编写。

mock 对象 单测

moco 启动

java -jar ./moco-runner-0.12.0-standalone.jar http -p 8888 -c demo.json

demo

[
  {
    "description": "My mock demo",
    "request": {
      "uri":"/"
    },
    "response": {
      "text": "Moco demo is running"
    }
  }
]
get
热部署:服务不用停止,就可以完成升级。
[
  {
    "description":"模拟一个没有参数的get 请求",
    "request":{
      "uri": "/getdemo",
      "method": "get"
    },
    "response": {
      "text": "这是一个没有参数的get请求"
    }
  },
  {
    "description": "模拟一个带参数的get请求",
    "request": {
      "uri": "/getwithparam",
      "method": "get",
      "queries": {
        "name": "zhangsan",
        "age": "18"
      }
    },
    "response": {
      "text": "hello zhangsan!!!!"
    }
  }
]
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!