Mock interface testing tool -moco runner

mock tests : mock test is in the testing process, some not easy to construct the object or not easily accessible, with a virtual object is to create a test method for testing. Many of these frameworks, some are achieved through coded, and some can directly edit files directly, moco-runner in two ways described in this article can be.

download link

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

I saw a jar suffix, indicating that the file needs to run java environment, do not know can find relevant information in advance to build a good environment java

How to use moco-runner, for example, we tested the login interface, you can put the mock interfaces file login.json

login.json reads as follows:

[

  {

   "Description": "get it is with a request parameter"

   "request":{

     "uri":"/login",

     "method":"get",

     "queries":{

       "name":"zhangsan",

       "pwd":"123456"

     }

   },

   "response":{

     "Text": "This is a return with arguments get request"

     "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 极光老师

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

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

Guess you like

Origin www.cnblogs.com/testfan2019/p/12177102.html