zoukankan      html  css  js  c++  java
  • 接口测试Mock利器-moco runner

    mock测试:mock测试就是在测试过程中,对于某些不容易构造或者不容易获取的对象,用一个虚拟的对象来创建以便测试的测试方法。这样框架很多,有的是通过编码实现,有的可以直接编辑文件直接提供,本文介绍的moco-runner两种方式都可以。

    下载地址

    http://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/0.12.0/

    一看到jar后缀,说明运行该文件需要java环境,不了解的可以找相关资料提前把java环境搭建好

    如何使用 moco-runner,例如我们测试登录接口,可以将mock接口放到login.json文件中

    login.json内容如下:

    [

      {

       "description":"这是一个带参数的get请求",

       "request":{

         "uri":"/login",

         "method":"get",

         "queries":{

           "name":"zhangsan",

           "pwd":"123456"

         }

       },

       "response":{

         "text":"返回这是一个带参数的get请求",

         "headers":{

           "Content-Type":"text/html;charset=gbk"

         }

       }

     }

    ]

    格式要写正确,中括号、大括号一定要有,description是描述,request是请求,uri是请求路径,response是返回结果,text是返回的是文本类型内容

    "headers":{

           "Content-Type":"text/html;charset=gbk"

     }

    解决工具中文返回乱码问题

    启动moco-runner命令如下:

    java -jar moco-runner-0.12.0-standalone.jar http -p 8081 -c login.json

    参数说明:

    java -jar 是启动jar文件命令

    http -p 是访问协议和访问端口号

    -c 是模拟的接口文件

    启动效果如下

    PostMan 模拟测试如下

    Post请求如何模拟呢?

    {

       "description":"这是一个带参数的post请求,请求参数格式是key:value,不能使用queries,要使用forms",

       "request":{

         "uri":"/loginpost",

         "method":"post",

         "forms":{

           "name":"qinzhenxia",

           "pwd":"123456"

         }},

         "response":{

           "text":"这是一个带表单参数的post请求",

           "headers":{

             "Content-Type":"text/html;charset=gbk"

           }

         }

    }

    所有接口可以维护在一个文件,也可以多个里面

    作  者:Testfan 极光老师

    出  处:微信公众号:自动化软件测试平台

    版权说明:欢迎转载,但必须注明出处,并在文章页面明显位置给出文章链接

  • 相关阅读:
    45、linux shell命令,ldconfig
    47、linux shell,ln链接
    43、linux shell命令,chmod
    39、linux 进程管理
    46、linux shell命令,chkconfig
    40、linux shell常用函数mkdir,rmdir,mount
    26、linux 几个C函数,nanosleep,lstat,unlink
    38、linux shell常用函数,nice
    44、linux shell命令,ldd
    41、linux shell常用函数,lsof
  • 原文地址:https://www.cnblogs.com/testfan2019/p/12177102.html
Copyright © 2011-2022 走看看