• 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---------------两种格式





























  • 相关阅读:
    (转)kubernetes更新操作详解--kubectl apply
    awk做统计和计算平均值
    kvm虚拟化
    容器(转
    使用python3来实现简易web服务
    12306接口
    python3中的venv环境
    markdown 插入表格
    面向对象编程——类(class)2
    开发纯ndk程序之环境搭配
  • 原文地址:https://www.cnblogs.com/520502-thy/p/15087821.html
Copyright © 2020-2023  润新知