1.业务场景
利用RobotFramework实现一个简单的接口测试实践。
2.知识点梳理
(1)接口测试
(2)封装
(3)断言
3.说明
思维导图梳理了接口测试环境的要求和一个简单的用例实践。
4.思维导图

5.代码详解
(1)simble_test_demo.robot
*** Settings ***
Documentation http请求Demo
Library Collections
Library RequestsLibrary
*** Variables ***
${host} http://httpbin.org
*** Test Cases ***
Post 请求Demo
[Tags] Post main
${data} Create Dictionary name=Detector age=18
create session httpbin ${host}
${response} post request httpbin /post params=${data}
should be equal as integers ${response.status_code} 200
${resp} to json ${response.content}
should not be empty ${resp["args"]}
dictionary should contain key ${resp["headers"]} Host
dictionary should contain value ${resp["headers"]} httpbin.org
Get 请求Demo
[Tags] Get
${data} Create Dictionary name=Detector age=18
create session httpbin ${host}
${response} get request httpbin /get params=${data}
should be equal as integers ${response.status_code} 200
${resp} to json ${response.content}
should not be empty ${resp["args"]}
dictionary should contain key ${resp["headers"]} Host
dictionary should contain value ${resp["headers"]} httpbin.org
原文:https://www.cnblogs.com/ioyuki/p/13636637.html