我正在尝试generators
在测试主体而不是config
部分内部定义。熟悉pyresttest
框架的人,生成器是为您的测试动态定义变量的一种方式文档
---
- config:
- testset: "Benchmark tests using test app"
# Variables to use in the test set
- variable_binds: {firstname: 'Gaius-Test', lastname: 'Baltar-Test'}
# Generators to use in the test set
- generators:
# Generator named 'id' that counts up from 10
- 'id': {type: 'number_sequence', start: 10}
- benchmark: # create new entities
- generator_binds: {user_id: id}
- name: "Create person"
- url: {template: "/api/person/$user_id/"}
- warmup_runs: 0
- method: 'PUT'
- headers: {'Content-Type': 'application/json'}
- body: {template: '{"first_name": "$firstname","id": "$user_id","last_name": "$lastname","login": "test-login-$id"}'}
- 'benchmark_runs': '1000'
- output_format: csv
- metrics:
- total_time: total
- total_time: mean
如果您看到该示例,则生成器是在配置部分中定义的,因此该变量id
可用于下面定义的所有测试。我的要求是在测试体内定义所有生成器绑定,并想知道是否可能?如果有人能提供一个例子,我将不胜感激。我想要达到的目标如下:
- test: # create new entities
- generators:
# Generator named 'id' that counts up from 10
- 'id': {type: 'number_sequence', start: 100}
- generator_binds: {user_id: id}
- name: "Create person"
- url: {template: "/api/person/$user_id/"}
- warmup_runs: 0
- method: 'PUT'
- headers: {'Content-Type': 'application/json'}
- body: {template: '{"first_name": "$firstname","id": "$user_id","last_name": "$lastname","login": "test-login-$id"}'}
- 'benchmark_runs': '1000'
- output_format: csv
- metrics:
- total_time: total
- total_time: mean
从文档
生成器输出可能会在测试中使用“生成器绑定”绑定到变量
生成器必须在 TestSet 配置中按名称声明才能使用
每个 HTTP 调用生成器绑定评估一次:每个测试仅评估一次,对于基准测试生成器绑定多次仅适用于声明它们的测试/基准。仅在评估绑定时生成新值。