TDL测试描述语言设计方案
数据库场景下_id可为数字字符串,MongoDB场景可使用UUID,框架场景可使用包.模块.方法路径
步骤定义规范
- method:操作关键字(
库.方法格式) - args:支持数值/字符串/数组/对象类型,对象作为关键字参数,其他按位置参数传递
- store:变量存储(对象格式)
- excepted:预期结果(数组或对象)
示例展示
示例1-接口测试
{
"name": "test_api_demo",
"priority": 1,
"tags": ["http", "api-test"],
"timeout": 100,
"setups": [
{"method": "Http.Get", "args": {"url": "/get","params": {"a": 1, "b": 2, "c": 3}}}
],
"teardowns": [
{"method": "Http.Get", "args": {"url": "/get","params": {"a": 1, "b": 2, "c": 3}}}
],
"steps": [
{"method": "Http.Get", "args": {"url": "/get","params": {"a": 1, "b": 2, "c": 3}}},
{"method": "Http.Post", "args": {"url": "/post", "json": {"name": "Kevin"}}},
{"method": "Http.Get", "args": {"url": "/get", "params": {"a": 1, "b": 2, "c": 3}},
"store": {"url": "$.url"}, "excepted": [{"AssertEqual": ["$url", "/get"]}]
]
}
示例2-UI测试
{
"name": "test_web_ui_demo",
"steps": [
{"method": "Page.Open", "args": ["https://www.baidu.com/"]},
{"method": "Page.InputTo", "args": ["id","kw", "helloworld"], "store": {"value1": "//[@id=\"kw\"]/@value"}},
{"method": "Page.Click", "args": ["id","su"]}
]
}
示例3-SSH操作
{
"name": "test_ssh_demo",
"steps": [
{"method": "SSH.Execute", "args": "echo hello"},
{"method": "SSH.GET", "args": ["/path/a.txt", "/local_path/a.txt"]}
]
}
测试集定义
- name:集名称(必填字符串)
- description:集描述(字符串)
- priority:默认优先级(整数)
- tags:默认标签列表(数组)
- timeout:默认超时时间(秒)
- setups:默认前置操作(对象数组)
- teardowns:默认后置操作(对象数组)
- setups-suite:集级前置(对象数组)
- teardowns-suite:集级后置(对象数组)
- tests:用例列表(对象数组)
- filter:过滤器(对象)
- _id:唯一标识(计算生成)
- _path:文件路径
测试集实现模式
- 原生定义模式
- 动态导入模式
示例数据1-原生定义
{
"name": "testsuite_01",
"description": "测试集说明",
"tags": ["ui-test"],
"priority": 1,
"tests": [
{
"name": "test_web_ui_demo",
"steps": [
{"method": "Page.Open", "args": ["https://www.baidu.com/"]},
{"method": "Page.InputTo", "args": ["id","kw", "helloworld"], "store": {"value1": "//[@id=\"kw\"]/@value"}},
{"method": "Page.Click", "args": ["id","su"]}
]
}
]
}
示例数据2-目录导入
{
"name": "testsuite_01",
"tests": [{"path": "./testcases"}],
"filter": {
"priorities": [],
"status": [],
"owner": [],
"include_tags": [],
"exclude_tags": [],
"exclude_names": []
},
}
测试报告定义
- title:报告标题(必填字符串)
- description:报告说明(字符串)
- summary:汇总信息(对象)
- details:执行详情(对象数组)
- _id:唯一标识(计算生成)
- _path:文件路径
示例模板
{
"title": "test_report",
"summary": {
"start_at": "2015-02-03 12:00:00.000",
"end_at": "2015-02-03 12:01:00.00",
"total": 12
},
"details": [
{}
]
}
实现规范
- 关键字命名:大驼峰格式(兼容Golang公开函数)
- 内置方法:Print/Log
- 断言方法:AssertEqual/AssertTrue/AssertFalse/AssertNone/AssertNotNone
关键字库实现
import tdl
import requests
@tdl.library
class Http:
def Get(url, **kwargs):
pass
自定义关键字映射
export TDL_KEY_EXCEPTED=verify
export TDL_KEY_STORE=register
export TDL_KEY_TESTS=testcases
待解决问题
- 库导入优化
- DDT数据驱动设计
- 执行顺序控制(随机/顺序)
- 并发执行支持
- 多主题报告支持
- 多格式报告支持(XML/JSON/Console/HTML)
- 其他格式转换支持
参考项目
- tdl
- runnerz
- stepz
- unitplus
- HttpRunner-1.5.6复刻版
- 30行接口框架实现