mcpField
T
test-failure-investigator

test-failure-investigator

github.com/proffesor-for-testing测试与质量51965 次安装今天更新
代码仓库

关于 test-failure-investigator

面向开发者和测试 Agent 的测试故障排查技能,按步骤复现并分类失败,缩小原因范围,并整理调查报告。

主要功能

  1. 01区分回归、偶发、环境或暂时性失败
  2. 02通过多次运行复现测试
  3. 03调查代码变更与可能根因
  4. 04生成结构化故障报告
  5. 05推荐后续测试技能

适用场景

  1. 01排查新出现的失败测试
  2. 02确认失败是否间歇发生
  3. 03追踪回归与近期代码变更的关系

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/proffesor-for-testing/agentic-qe --skill test-failure-investigator

安装后在 Claude Code 中输入/test-failure-investigator确认已加载。

详细介绍

测试失败调查员

用于系统化调查测试失败的运行手册式技能。给定一个失败的测试,确定根本原因并建议后续操作。

激活

/test-failure-investigator [test-name-or-file]

调查流程

步骤 1:对失败进行分类

运行测试 3 次并分类:

结果模式分类操作
持续失败回归或环境问题继续步骤 2
间歇性失败不稳定测试跳至步骤 4
现在通过暂时性问题检查 CI 日志和环境差异
# Run test 3 times
for i in 1 2 3; do npx jest {{test_file}} 2>&1 | tail -5; echo "--- Run $i ---"; done
步骤 2:缩小范围
# When did it start failing?
git log --oneline -20 -- {{related_source_files}}

# What changed recently?
git diff HEAD~5 -- {{related_source_files}}

# Does it fail in isolation?
npx jest {{test_file}} --testNamePattern="{{test_name}}"

# Does it fail with other tests?
npx jest --runInBand  # sequential execution
步骤 3:根本原因分析
症状可能原因调查方法
超时网络/数据库依赖检查外部服务是否可用
断言不匹配逻辑变更比较预期值与实际值,检查 git blame
导入错误依赖变更检查 package.json 变更,运行 npm ci
权限被拒绝环境问题检查文件权限和 Docker 卷
内存不足资源泄漏使用 --detectOpenHandles 进行分析
步骤 4:不稳定测试调查
# Run 10 times to confirm flakiness
for i in $(seq 1 10); do npx jest {{test_file}} --forceExit 2>&1 | grep -E 'PASS|FAIL'; done

# Common flaky causes:
# - Shared state between tests (missing cleanup)
# - Time-dependent assertions (use fake timers)
# - Race conditions (missing await)
# - Port conflicts (use random ports)
# - Order dependency (run with --randomize)
步骤 5:报告
## Test Failure Report
- **Test**: {{test_name}}
- **File**: {{test_file}}
- **Classification**: Regression / Flaky / Environment / Transient
- **Root Cause**: {{description}}
- **First Failed**: {{commit_hash}} ({{date}})
- **Fix**: {{recommended_action}}
- **Verified**: [ ] Fix applied and test passes 3x consecutively

组合使用

调查后,与以下技能组合使用:

  • /bug-reporting-excellence — 如果发现回归,则提交错误报告
  • /regression-testing — 如果发现回归,则将其加入回归测试套件
  • /qe-test-execution — 修复后重新运行测试

注意事项

  • Agent 可能会在未运行测试的情况下猜测根本原因——务必先复现问题
  • “在我的机器上可以运行”不是诊断结果——比较环境(node 版本、操作系统、依赖项)
  • 通过率为 9/10 的不稳定测试仍会被 CI 报告为“通过”——运行 10 次以上
  • 测试隔离失败是不稳定测试的首要原因——检查 beforeAll/afterAll 中是否存在共享状态

评论

支持 Markdown