死的简单api单元测试
majime的Python项目详细描述
/马吉梅/
名词
- 一个能把事情办好的认真可靠的人
- 死的简单api单元测试
它是做什么的?
- majime在api端点上运行测试用例
- 测试用例在yaml文件中定义
- majime可以根据夸张的规格生成测试用例
安装
pip install majime
在python3环境中
用法
Usage:
-f Load and run tests from YAML file
Example: majime -f test.yaml
-g Generate test suite (YAML) from Swagger document
Example: majime -g http://api.example.com/swagger.json
Switches:
-j JSON output
-d Dry-Run, do not execute tests - good for testing your YAML file
示例
从swagger生成测试用例
majime -g http://backend.yoisho.dob.jp/fx/swagger
Title: Yoisho Currency Exchange
Host: backend.yoisho.dob.jp
Base Path: /fx
Scheme: http
Path: /currency
Method: GET
Description: Get the FX rate for desired currency
Query Parameters: ['currency']
Expected Response: 200
生成的输出文件
Base: "http://backend.yoisho.dob.jp/fx"
Tests:
# GET - Get the FX rate for desired currency
- path: "/currency?currency=USD"
method: "GET"
headers: ""
expect-response: "200"
expect-body: "json"
运行测试用例
Base: "http://backend.yoisho.dob.jp/fx"
Tests:
# GET - Get the FX rate for desired currency
- path: "/currency?currency=USD"
method: "GET"
headers: ""
expect-response: "200"
expect-body: "json"
修改参数使其有意义,在本例中为xxx->;美元。
majime -f Yoisho_Currency_Exchange-*.yaml
GET http://backend.yoisho.dob.jp/fx/currency?currency=USD
HTTP 200
查看examples。