用moco工具mock接口

 1.下載moco  jar包,下載地址:https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/0.11.0/

2.創建Json文件mock接口

3.運行命令

java -jar ./moco-runner-0.11.0-standalone.jar 協議 -p 端口號 -c 文件名.json

協議:一般是http,如果用到其他的協議填寫對應的即可

端口號:隨便寫,比如8888

文件名.json:創建的json文件名

4.用瀏覽器或jmeter等相關工具驗證是否正確

5.帶參數的get請求與post請求的不同之處:get用queries  post用forms

[

{
    "description": "模擬一個有參數的get請求",
    "request": {
        "uri": "/getwithparam",
        "method": "get",
        "queries": {
            "name": "huhansan",
            "age": "18"
        }
    },
    "response": {
        "text": "這是一個有參數的get request"
    }
},
{
    "description": "模擬一個有參數的get請求",
    "request": {
      "uri": "/postwithparam",
      "method": "post",
      "forms": {
        "name": "huhansan",
        "sex": "man"
      }
    },
    "response": {
      "text": "這是一個有參數的post request"
    }
  }
]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章