zoukankan      html  css  js  c++  java
  • moco---对应mock测试

    地址:https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/

    下载:moco-runner-0.11.0-standalone.jar

    配置

    java -jar ./moco-runner-0.11.0-standalone.jar http -p 8888 -c startup1.json

    --http为请求

    --startup1.json为相对路径下的json文件

    ------startup1.json文件内容------------

    [
    {
    "description":"这是我们的第一个mock例子",
    "request":{
    "uri":"/demo"
    },
    "response":{
    "text":"第一个moco框架demo",
    "headers":{"Content-Type":"text/html;charset=gbk"}//处理乱码
    }
    }
    ]

    --------------get请求(没有参数/存在参数)---------------
    [
    {
    "description":"这是我们的第一个没有get请求参数例子",
    "request":{
    "uri":"/getdemo",
    "method":"get"
    },
    "response":{
    "text":"第一个没有参数的get请求",
    "headers":{"Content-Type":"text/html;charset=gbk"}
    }
    },
    {
    "description":"这是我们的第一个存在get请求参数例子",
    "request":{
    "uri":"/getwithParamter",
    "method":"get",
    "queries":{
    "name":"zhangsann",
    "age":"18"}
    },
    "response":{
    "text":"我胡汉三又回来了",
    "headers":{"Content-Type":"text/html;charset=gbk"}

    }
    }
    ]

    --http://localhost:8888/getdemo
    -----http://localhost:8888/getwithParamter?name=zhangsann&age=18


    --------------------------POST------------------------
    [
    {
    "description":"这是我们的第一个post的mock例子",
    "request":{
    "uri":"/demo",
    "method":"post"
    },
    "response":{
    "text":"第一个moco框架postdemo",
    "headers":{"Content-Type":"text/html;charset=gbk"}
    }
    }
    ]
    ----对应jmeter的请求结果

    ----------------------------------post有参数的--------------------------------------

    { "description":"这是我们的第一个有参数post的mock例子",
    "request":{
    "uri":"/postParamterDemo",
    "method":"post",
    "forms":{
    "name":"hun",
    "age":"16"

    }
    },
    "response":{
    "text":"第一个moco框架postdemo有参数",
    "headers":{"Content-Type":"text/html;charset=gbk"}
    }
    }

     ----------------带cookies的get请求---------------------------

    [
    {
    "description":"这是我们的第一个get的mock例子",
    "request":{
    "uri":"/get/with/Cookies",
    "method":"get",
    "cookies":{
    "login":"true"
    }
    },
    "response":{
    "text":"这是一个需要cookies的get请求",
    "headers":{"Content-Type":"text/html;charset=gbk"}
    }
    }

    ]

    配置的cookie元件

    ----------------------带cookies的post-----------------------------------------------------

    {
    "description":"这是我们的第一个post的mock例子",
    "request":{
    "uri":"/post/with/Cookies",
    "method":"post",
    "cookies":{
    "login":"true"
    },
    "json":{
    "name":"hun",
    "age":"18"
    }
    },
    "response":{
    "status":200,
    "json":{
    "hun":"success",
    "status":"1"
    },
    "headers":{"Content-Type":"text/html;charset=gbk"}
    }
    }



    ----------------------------加入header------------------------------------------------
    [

    {
    "description":"这是我们的第一个post的mock例子",
    "request":{
    "uri":"/post/with/Cookies",
    "method":"post",
    "headers":{
    "content-type":"application/json"
    },
    "cookies":{
    "login":"true"
    },

    "forms":{
    "name":"hun",
    "age":"18"
    }
    },
    "response":{
    "json": {
    "hun": "success",
    "status": "1"
    }
    }
    }

    ]
    --------forms或者json---------------两种格式





























  • 相关阅读:
    使用PHP QR Code生成二维码
    thinkphp伪静态(url重写)
    jQuery Ajax 实例 ($.ajax、$.post、$.get)
    php各种编码集详解和以及在什么情况下进行使用
    PHP无限极分类生成树方法,无限分级
    PHP5: mysqli 插入, 查询, 更新和删除 Insert Update Delete Using mysqli (CRUD)
    Js获取当前日期时间及其它操作
    Spring源码解读Spring IOC原理
    java多线程系列六、线程池
    springMVC中ajax的实现
  • 原文地址:https://www.cnblogs.com/520502-thy/p/15087821.html
Copyright © 2011-2022 走看看