接口自动化moco使用

 

 

1.下载mock,地址http://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/0.11.0/(选择moco-runner-0.11.0-standalone.jar)

2.把下好的jar包放在同一个目录下,moco启动命令;

java -jar ./moco-runner-0.11.0-standalone.jar http -p 8888 -c startup1.json
http代表协议,-p端口号,-c配置文件

3.发送一个get请求:

[
  {
    "description": "这是get不带参数请求例子",
    "request": {
      "uri": "/getdemo",
      "method": "get"
    },
    "response": {
      "text": "这是一个没有参数的get请求",
      "headers": {
        "Content-Type": "text/html;charset=gbk"
      }
    }
  },
  {
    "description":"模拟一个带参数的get请求",
    "request": {
      "uri": "/get",
      "method": "get",
      "queries": {
        "name": "hu",
        "age": "18"
      }
    },
      "response":{
        "text":"我胡汉三回来了",
        "headers": {
          "Content-Type": "text/html;charset=gbk"
        }
      }
    }

]

4.post请求(带参数的话key用forms,get用queries):

[
  {
    "description":"模拟一个post请求",
    "request":{
      "uri":"/postdemo",
      "method":"post"
    },
    "response":{
      "text":"这是一个post请求",
      "headers": {
        "Content-Type": "text/html;charset=gbk"
      }
    }
  },
  {
    "description":"模拟一个post带参数请求",
    "request":{
      "uri":"/postparam",
      "method":"post",
      "forms":{
        "name":"jack",
        "age":"1"
      }
    },
    "response":{
      "text":"带参数的响应",
      "headers": {
        "Content-Type": "text/html;charset=gbk"
      }
    }
  }
]

 

 

 

 

5.get带cookies的请求(使用jmeter需要添加domain和path信息)

[
  {
    "description":"这是一个带cookies的get请求",
    "request":{
      "uri":"/get/cookies",
      "method":"get",
      "cookies":{
        "login":"true"
      }
    },
    "response":{
      "text":"这是一个带cookies请求的响应"
    }
  },
  {
    "description":"这是一个带cookies的post请求",
    "request":{
      "uri":"/post/cookies",
      "method":"post",
      "cookies":{
        "login":"true"
      },
      "json":{
        "name":"hu",
        "age":"18"
      }
    },
    "response": {
      "status": "200",
      "json": {
        "hu": "success",
        "status":"1"
      }
    }
  }
]

 

.带header的请求

[
  {
    "description": "模拟一个post带参数请求",
    "request": {
      "uri": "/post/header",
      "method": "post",
      "headers":{
        "content-type":"application/json"
      },
      "forms": {
        "name": "jack",
        "age": "1"
      }
    },
    "response":{
      "text":"带头信息的响应",
      "headers": {
        "Content-Type": "text/html;charset=gbk"
      }
    }
  }
]

 

 

你可能感兴趣的:(接口自动化)