Skip to Content
Testing自定义断言

自定义断言

自定义断言将需求转化为 VM 工具可以执行的命令。 将它们用于小型默认套件未涵盖的行为。

结构

每个定制测试组都需要一个描述和一个或多个结构化的 断言:

{ "description": "Verify the web service", "category": "application", "assertions": [ { "type": "service_running", "description": "Nginx is active", "params": { "service": "nginx" }, "expected_visual": "The evidence panel shows nginx active" }, { "type": "http_responds", "description": "Local health endpoint responds", "params": { "url": "http://localhost/health", "status": 200 } } ] }

description 在组和每个断言上都是必需的。 on_vm 在多VM测试环境中选择VM ID;没有它,跑步者会使用 primaryexpected_visual 在以下情况下提供预期的屏幕截图状态: 视觉证据门已激活。

围绕结果设计断言

  • 使用 service_running 检查服务,而不仅仅是其包是否存在。
  • 在测试外部路由之前检查本地端点。
  • 使用 file_contains 作为一个稳定的配置事实,而不是一个完整的文件 快照会在无害的格式化时中断。
  • 仅将 command_succeeds 与确定性、非交互式命令一起使用。
  • 仅在需要时才发出长命令 timeout_seconds。执行器夹 命令超时为 1–1,800 秒。
  • 切勿将凭据放入命令、描述、预期输出或 URL 中; 这些字段可以出现在证据和日志中。

失败语义

未知类型当前被配方模型接受,但成为 error 当执行程序找不到处理程序时。省略的已知断言 在测试计划组装期间可以删除所需的参数,并发出警告。 因此,在之前验证配方并检查具体化的测试计划 开始构建。

如果 on_vm 命名的 VM 不存在,则断言为 skipped。不 将 skippederror 视为验证成功。

多虚拟机示例

{ "description": "Client reaches the API node", "assertions": [ { "type": "http_responds", "description": "API health is reachable from the client", "on_vm": "client", "params": { "url": "http://api:8080/health", "status": 200 } } ], "environment": { "vms": [ { "vm_id": "client", "role": "client", "networks": ["lan"] }, { "vm_id": "api", "role": "server", "networks": ["lan"] } ], "networks": [ { "network_id": "lan", "type": "isolated", "dhcp": true } ] } }

VM 名称解析取决于测试拓扑及其发现的地址。 在运行中确认渲染的拓扑和断言的解析命令 证据。

对于每个支持的类型和参数,请参阅 Assertion types