Files
cursor/plans/测试报告可追踪输出_4fd907ad.plan.md
ray zhou f71a5c59af ok
2026-05-29 11:21:40 +08:00

4.0 KiB
Raw Blame History

name, overview, todos, isProject
name overview todos isProject
测试报告可追踪输出 在现有 WalletRegisterBetWinTest 上增加“可追踪测试报告”:每次执行输出并落盘 uid/round_id/biz_id/余额快照,失败时可直接按用户复现。
id content status
add-reporter-support 新增 WalletTestRunContext 与 WalletTestReporterJSON+Markdown 落盘) completed
id content status
wire-test-class 改造 WalletRegisterBetWinTest记录 uid/round/biz_idtearDown 输出摘要 completed
id content status
config-and-doc phpunit.xml 增加 WALLET_TEST_UID/REPORT_DIR更新 doc 执行说明 completed
id content status
verify-run 容器执行 phpunit 并确认控制台+报告文件含 uid completed
false

钱包集成测试可追踪报告方案

问题

当前 tests/Feature/WalletRegisterBetWinTest.php 每个用例都会 makeUid() 生成随机用户PHPUnit 默认只显示 OK (3 tests, 37 assertions)看不到本次用了哪个 uidround_idbiz_id,联调排障和 DB 核对都不方便。

目标

  • 跑完测试后,控制台能看到每个用例的测试用户与关键业务 ID。
  • 落盘一份报告JSON + 可读 Markdown便于复制 uid 去查库或手工 curl 复现。
  • 可选:通过环境变量固定 uid,便于反复验证同一用户。

实现方案

1. 新增测试上下文与报告器

新增 tests/Support/WalletTestRunContext.php

  • 字段:testName, uid, currency, roundId, bizIdsregister/bet/win_mid/win_final, traceId, steps[](每步 API、code、余额快照, status, errorMsg

新增 tests/Support/WalletTestReporter.php

  • startRun() / recordStep() / finishTest() / writeReport()
  • 报告目录:runtime/test-reports/(文件名含时间戳,如 wallet-register-bet-win-20260515-160530.json 与同名 .md
  • Markdown 表格示例列:用例名 | uid | round_id | biz_id 列表 | 结果 | 最终余额(deposit/withdraw/b)

2. 改造现有 Feature 测试

tests/Feature/WalletRegisterBetWinTest.php 中:

  • setUp():初始化 reporter若存在 WALLET_TEST_UID 则使用该固定 uid否则继续随机
  • 每个 test* 开始:创建 WalletTestRunContext 并记录 uid/round_id/biz_id。
  • postJson() / wallet():成功后把 code、关键 data、查询余额写入 steps
  • tearDown():标记 pass/fail调用 writeReport()向 STDOUT 打印一行摘要PHPUnit 控制台可见),例如:
    • [WalletTest] testRegisterBetWinFlow uid=90012345 round=r_... bet=bet_... => PASS

失败时 assertion message 附带 context 摘要,便于一眼定位用户。

3. 配置与文档

  • phpunit.xml 增加可选 env
    • WALLET_TEST_UID(空=随机)
    • WALLET_TEST_REPORT_DIR(默认 runtime/test-reports
    • WALLET_TEST_VERBOSE1 时打印每步明细)
  • 更新 doc/register-bet-win-test.md §7
    • 报告路径说明
    • 固定 uid 复现示例:WALLET_TEST_UID=90012345 docker compose exec ... phpunit ...

4. 执行验证

容器内执行:

docker compose exec -T -w /app/www/ray/slot-wallet php82 php vendor/bin/phpunit --filter WalletRegisterBetWinTest

验收:

  • 控制台出现每个用例的 uid 摘要行
  • runtime/test-reports/ 生成 .json + .md
  • 测试仍全部通过3 tests

报告结构示意

flowchart LR
    testCase[WalletRegisterBetWinTest] --> context[WalletTestRunContext]
    context --> reporter[WalletTestReporter]
    reporter --> stdout[ConsoleSummary]
    reporter --> jsonFile[runtime/test-reports/*.json]
    reporter --> mdFile[runtime/test-reports/*.md]

不在本阶段做的(可选后续)

  • HTML 可视化报告、CI artifact 上传
  • DB 直连断言wallet_log / wallet_fund_lot