zoukankan      html  css  js  c++  java
  • Moco框架

    1、下载地址:https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/0.11.0/

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

    2、moco启动实例:

      在项目上创建目录moco,拷贝下载好的jar包到新建目录,新建mock文件startup.json:

    [
      {
        "description":"启动举例",
        "request":{
          "uri":"/demo"
        },
        "response":{
          "text":"demostarted"
        }
    
      }
    ]
    mock文件实例

      cd命令切换到新建目录:

      mock启动命令:java -jar  moco-runner-0.11.0-standalone.jar http -p 8888 -c startup.json

    3、get请求方法实现mock文件示例:

    [
      {
        "description":"模拟一个没有参数get请求",
        "request":{
          "uri":"/getdemo",
          "method":"get"
        },
        "response":{
          "text":"这是一个没有参数的get请求"
        }
    
      },
      {
        "description":"这是一个带参数get请求",
        "request":{
          "uri":"/getwithparam",
          "method":"get",
          "queries":{
            "name":"huhansan",
            "sex":"20"
          }
        },
        "response":{
          "text":"我胡汉三又回来啦!!!!"
        }
    
      }
    
    ]
    get方法mock

    4、post请求方法实现mock文件示例:

    [
      {
        "description":"模拟一个post请求",
        "request":{
          "uri":"/postdemo",
          "method":"post"
        },
        "response":{
          "text":"这是我的第一个mock的post请求"
        }
      },
      {
        "description":"这是一个带参数的post请求",
        "request":{
          "uri":"/postwithparam",
          "method":"post",
          "forms":{
            "name":"huhansan",
            "sex":"man"
          }
        },
        "response":{
          "text":"我胡汉三带着参数来啦!!!"
    
        }
      }
    
    ]
    post方法mock文件

    5、带cookie的get、post请求和返回cookie的

    [
      {
        "description":"这是一个会返回cookies信息的get请求",
        "request":{
          "uri":"/getCookies",
          "method":"get"
        },
        "response":{
          "cookies":{
            "login":"true"
          },
          "text":"恭喜你获得cookies信息成功"
        }
    
    
      },
    
    
      {
        "description":"这是一个带cookies信息的get请求",
        "request":{
          "uri":"/get/with/cookies",
          "method":"get",
          "cookies":{
            "login":"true"
          }
        },
        "response":{
          "text":"这是一个需要携带cookies信息才能访问的get请求"
        }
      },
      {
        "description":"这是一个带cookies信息的post请求",
        "request":{
          "uri":"/post/with/cookies",
          "method":"post",
          "cookies":{
            "login":"true"
          },
          "json":{
            "name":"huhansan",
            "age":"18"
          }
        },
        "response":{
          "status":200,
          "json":{
            "huhansan":"success",
            "status":"1"
          }
        }
      }
    
    ]
    cookie

    6、请求头header:

    [
      {
        "description":"这是一个带header信息的post请求",
        "request":{
          "uri":"/post/with/headers",
          "method":"post",
          "headers":{
            "content-type":"application/json"
          },
          "json":{
            "name":"wanglaosi",
            "sex":"woman"
          }
        },
        "response":{
          "json":{
            "wanglaosi":"success",
            "status":"1"
          }
        }
    
      }
    
    ]
    header

    7、重定向redirect

    [
      {
        "description":"重定向到百度",
        "request":{
          "uri":"/redirect"
        },
        "redirectTo":"http://www.baidu.com"
      },
      {
        "description":"重定向到一个自己的网页上",
        "request":{
          "uri":"/redirect/topath"
        },
        "redirectTo":"/redirect/new"
      },
      {
        "description":"这是被重定向到的请求",
        "request":{
          "uri":"/redirect/new"
        },
        "response":{
          "text":"重定向成功啦"
        }
      }
    
    ]
    redirect
  • 相关阅读:
    [ABC200E] Patisserie ABC 2
    [CF1521E] Nastia and a Beautiful Matrix
    [CF1498D] Bananas in a Microwave
    [CF1515B] Phoenix and Puzzle
    [CF1519C] Berland Regional
    [CF1519B] The Cake Is a Lie
    [ZONe Energy Programming Contest C] MAD TEAM
    [洛谷P7480] Reboot from Blue
    [CF1508A] Binary Literature
    1371. 货币系统
  • 原文地址:https://www.cnblogs.com/wangkc/p/10847863.html
Copyright © 2011-2022 走看看