Skip to content

结果验证器

结果验证器用于验证整个测试步骤的执行结果是否符合预期。

配置项

yaml
testclass: result # result 验证器,用于验证整个取样结果是否符合预取
expected: 200  # 期望值
rule: ==   # 验证规则
strict: false # 是否严格验证,默认否:忽略大小写验证

参数说明

参数必填说明
testclass验证器类型,固定值为 result
expected期望值
rule验证规则,支持多种比较操作
strict是否严格验证,默认为 false(忽略大小写)

使用示例

验证HTTP请求成功

yaml
testclass: http
title: 用户登录
config:
  method: POST
  protocol: http
  host: api.example.com
  path: /login
  body:
    username: testuser
    password: testpass
validators:
  - testclass: result
    expected: 响应消息内容
    rule: '=='

验证数据库操作影响行数

yaml
testclass: jdbc
title: 更新用户信息
config:
  url: jdbc:mysql://localhost:3306/testdb
  username: testuser
  password: testpass
  sql: UPDATE users SET name = 'updated_user' WHERE id = 123
validators:
  - testclass: result
    expected: 1
    rule: '=='

验证消息队列发送成功

yaml
testclass: kafka
title: 发送订单创建消息
config:
  bootstrap_servers: localhost:9092
  topic: order-events
  key: order-123
  value: '{"orderId": 123, "status": "created"}'
validators:
  - testclass: result
    expected: true
    rule: '=='

支持的验证规则

结果验证器支持以下验证规则:

规则说明示例
==相等expected: 200, rule: "=="
eq_any任意一个相等expected: [200, 300], rule: "eq_any"
!=不相等expected: 404, rule: "!="
>大于expected: 0, rule: ">"
<小于expected: 10000, rule: "<"
>=大于等于expected: 0, rule: ">="
<=小于等于expected: 100, rule: "<="
contains包含expected: "success", rule: "contains"
any_contains包含任意一个expected: [success, false], rule: "any_contains"
not_contains不包含expected: "error", rule: "not_contains"
regex正则匹配expected: "^\\d{4}-\\d{2}-\\d{2}$", rule: "regex"
is_not_empty非空field: header.Content-Type, rule: "is_not_empty"
is_empty为空field: header.Content-Type, rule: "is_empty"
same_object对象匹配expected: {}, rule: "same_object"

Released under the MIT License.