haas的web api测试
usagi的Python项目详细描述
usagi是haas的插件,它添加了对发现web的支持 用yaml描述的api测试用例。
usagi需要haas v0.6.0或更高版本。
当前功能
- 使用yaml描述web api测试。
- 模板URL以避免重复项。
- 环境变量可以提供变量和目标主机名。
- yaml格式包含多个测试用例。
- 每个测试用例都是一组相关的测试。 对服务器的响应做出灵活的断言。
- 通过插件提供web api测试运行程序功能。
- 断言响应体的SHA256与预期值匹配。
- 在使用jqfilter进行比较之前筛选json响应体 语法:http://stedolan.github.io/jq/
插件
- 无功加载器
- 从环境加载
- 基于其他变量的模板字符串
- 从文件加载,纯文本或json
- 断言
- 断言状态代码
- assert头存在或与值或regexp匹配
待办事项
- 添加更多断言!
测试配置格式
- version:当前需要,但未验证(我们位于 v0.1.0.devN,毕竟)。
- config:通用测试用例配置。
- host:要测试的主机的名称(或IP)。
- 可以来自env、template、file,比如vars。
- scheme:用于连接到host 的方案(http,https)
- vars:所有测试用例的公共变量定义;格式化
作为变量名到类型和值的字典。
- 允许简单的字符串变量。
- 其他的则指定为键为typeto的字典 确定如何加载。
- host:要测试的主机的名称(或IP)。
- cases:测试用例的集合。每个案例包含多个测试
- name:测试用例的名称
- tests:单个测试的集合
- name:测试的名称
- url:与测试所依据的host相关的uri/路径 将被处决。
- method:用于测试的http方法。
- assertions:关于测试的断言列表。
示例测试
---version:'1.0'config:# Host is loaded as an environment variablehost:type:envenv:TEST_HOSTNAMEvars:# Simple string varapi_root:"/api/v1/json"# Template varmetadata:type:templatetemplate:"{api_root}/metadata"# Variable loaded as JSON from fileexpected_index:type:filefile:some_file.jsonformat:jsoncases:-name:"Basic"tests:-name:"TestrootURL"url:"/"assertions:-name:status_codeexpected:200-name:headerheader:Content-Typevalue:text/plain-name:"Acase"tests:-name:"Authenticationfailure"url:type:templatetemplate:"{metadata}/auth/required"parameters:method:GETheaders:Content-Type:application/jsonassertions:-name:status_codeexpected:401-name:headerheader:WWW-Authenticateregexp:"Basicrealm=.*"-name:"POSTjson"url:type:templatetemplate:"{metadata}/post"parameters:method:POSTbody:format:jsonlookup-var:falsevalue:some:["json-compatible","structure"]assertions:-name:status_codeexpected:204