Files
httprunner/docs/concept/nominal.md
2019-11-01 23:28:50 +08:00

67 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 测试用例testcase
从 2.0 版本开始HttpRunner 开始对测试用例的定义进行进一步的明确,参考 [wiki][wiki_testcase] 上的描述。
> A test case is a specification of the inputs, execution conditions, testing procedure, and expected results that define a single test to be executed to achieve a particular software testing objective, such as to exercise a particular program path or to verify compliance with a specific requirement.
概括下来一条测试用例testcase应该是为了测试某个特定的功能逻辑而精心设计的并且至少包含如下几点
- 明确的测试目的achieve a particular software testing objective
- 明确的输入inputs
- 明确的运行环境execution conditions
- 明确的测试步骤描述testing procedure
- 明确的预期结果expected results
对应地HttpRunner 的测试用例描述方式进行如下设计:
- 测试用例应该是完整且独立的,每条测试用例应该是都可以独立运行的;在 HttpRunner 中,每个 `YAML/JSON` 文件对应一条测试用例。
- 测试用例包含 `测试脚本``测试数据` 两部分:
- `测试用例 = 测试脚本 + 测试数据`
- `测试脚本` 重点是描述测试的 `业务功能逻辑`包括预置条件、测试步骤、预期结果等并且可以结合辅助函数debugtalk.py实现复杂的运算逻辑可以将 `测试脚本` 理解为编程语言中的 `类class`
- `测试数据` 重点是对应测试的 `业务数据逻辑`,可以理解为类的实例化数据;
- `测试数据``测试脚本` 分离后,就可以比较方便地实现数据驱动测试,通过对测试脚本传入一组数据,实现同一业务功能在不同数据逻辑下的测试验证。
## 测试步骤teststep
测试用例是测试步骤的 `有序` 集合,而对于接口测试来说,每一个测试步骤应该就对应一个 API 的请求描述。
## 测试用例集testsuite
`测试用例集``测试用例``无序` 集合,集合中的测试用例应该都是相互独立,不存在先后依赖关系的。
如果确实存在先后依赖关系怎么办,例如登录功能和下单功能。正确的做法应该是,在下单测试用例的前置步骤中执行登录操作。
```yaml
- config:
name: order product
- test:
name: login
testcase: testcases/login.yml
- test:
name: add to cart
api: api/add_cart.yml
- test:
name: make order
api: api/make_order.yml
```
## 测试场景
`测试场景``测试用例集` 是同一概念,都是 `测试用例``无序` 集合。
- 接口
- 测试用例集
- 参数
- 变量
- 测试脚本YAML/JSON
- debugtalk.py
- 环境变量
## 项目根目录
[wiki_testcase]: https://en.wikipedia.org/wiki/Test_case