analyze-tests

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Test Suite Analysis

测试套件分析

Perform a focused analysis of this project's test suite. Follow the procedural workflow below; use the rubric sections as reference when interpreting findings.
对该项目的测试套件进行针对性分析。遵循以下流程步骤;解读结果时可参考评分标准部分。

Usage

使用方法

When asked to analyze test quality:
当需要分析测试质量时:

1. Run coverage

1. 运行覆盖率检测

Establish baseline coverage (prefer lintro when available):
bash
uv run lintro tst    # runs tests with coverage when configured
If lintro is unavailable, use the project's native test command with coverage (
uv run pytest --cov
,
bun test --coverage
,
cargo llvm-cov
, etc.).
Note overall coverage percentage and files below threshold.
建立基准覆盖率(若可用,优先使用lintro):
bash
uv run lintro tst    # runs tests with coverage when configured
如果lintro不可用,使用项目原生的测试命令搭配覆盖率检测(
uv run pytest --cov
bun test --coverage
cargo llvm-cov
等)。
记录整体覆盖率百分比以及未达阈值的文件。

2. Find "nothing burger" tests

2. 查找“无意义”测试

Search for tests that assert little or trivially pass:
bash
undefined
搜索那些断言内容极少或轻易就能通过的测试:
bash
undefined

Empty or minimal assertions

Empty or minimal assertions

rg -U 'def test_\w+.*\n(\s+pass|\s+assert True|\s+assert 1 == 1)' --type py
rg -U 'def test_\w+.*\n(\s+pass|\s+assert True|\s+assert 1 == 1)' --type py

Tests with no expect/assert (JS/TS)

Tests with no expect/assert (JS/TS)

rg -n 'it(|test(' --type ts --type js -A 5 | rg -B2 '^\s*});?\s*$'
rg -n 'it(|test(' --type ts --type js -A 5 | rg -B2 '^\s*});?\s*$'

Placeholder / TODO tests

Placeholder / TODO tests

rg -n '(test_|it(|describe().*(skip|todo|pending|.only)' -i rg -n '@pytest.mark.skip|pytest.skip(' --type py

Flag tests that don't validate real behavior.
rg -n '(test_|it(|describe().*(skip|todo|pending|.only)' -i rg -n '@pytest.mark.skip|pytest.skip(' --type py

标记那些未验证实际行为的测试。

3. Find missing parametrization

3. 查找缺失的参数化

Detect copy-paste test patterns with similar names:
bash
undefined
检测存在复制粘贴模式、名称相似的测试:
bash
undefined

Similar test function names (Python)

Similar test function names (Python)

rg -n 'def test_\w+\w+\d+' --type py rg -n 'def test_(create|update|delete|get)_' --type py | sort
rg -n 'def test_\w+\w+\d+' --type py rg -n 'def test_(create|update|delete|get)_' --type py | sort

Repeated it() blocks with numeric suffixes (JS/TS)

Repeated it() blocks with numeric suffixes (JS/TS)

rg -n "it('.*\d+'" --type ts --type js

When multiple tests differ only by input values, recommend `@pytest.mark.parametrize`
or table-driven equivalents.
rg -n "it('.*\d+'" --type ts --type js

当多个测试仅输入值不同时,建议使用`@pytest.mark.parametrize`或表格驱动的等效方案。

4. Check isolation

4. 检查隔离性

Find shared mutable state and order-dependent tests:
bash
undefined
查找共享可变状态和依赖执行顺序的测试:
bash
undefined

Module-level mutable state in test files

Module-level mutable state in test files

rg -n '^[A-Z_]+\s*=\s*[]|^[a-z_]+\s*=\s*{}' tests/ --type py rg -n 'global |beforeAll|afterAll' tests/ -i
rg -n '^[A-Z_]+\s*=\s*[]|^[a-z_]+\s*=\s*{}' tests/ --type py rg -n 'global |beforeAll|afterAll' tests/ -i

Tests that modify shared fixtures or class state

Tests that modify shared fixtures or class state

rg -n 'self.\w+\s*=' tests/ --type py rg -n '@pytest.fixture.scope\s=\s*["\x27]session' --type py

Verify tests are independent and deterministic.
rg -n 'self.\w+\s*=' tests/ --type py rg -n '@pytest.fixture.scope\s=\s*["\x27]session' --type py

验证测试是否独立且具有确定性。

5. Fixture reuse

5. 复用夹具(Fixture)

Identify duplicated setup that should be shared:
bash
rg -n '@pytest\.fixture|def setUp|beforeEach' tests/ --type py
rg -n 'def test_' -A 15 tests/ --type py | rg -c 'client\s*=|db\s*=|setup\s*=' 
Look for repeated boilerplate across tests in the same file.
识别应共享的重复设置代码:
bash
rg -n '@pytest\.fixture|def setUp|beforeEach' tests/ --type py
rg -n 'def test_' -A 15 tests/ --type py | rg -c 'client\s*=|db\s*=|setup\s*=' 
查找同一文件中测试之间重复的样板代码。

6. Report gaps with specifics

6. 详细报告缺口

For each finding, include:
  • File path and test function name (e.g.,
    tests/test_auth.py::test_login_invalid
    )
  • Severity: Critical | Should Fix | Nice to Have
  • Concrete improvement (add parametrization, assert on behavior, extract fixture, etc.)
Summarize coverage gaps: untested modules, missing edge cases, and integration points without tests.

对于每个发现的问题,需包含:
  • 文件路径和测试函数名称(例如:
    tests/test_auth.py::test_login_invalid
  • 严重程度:Critical(严重) | Should Fix(应修复) | Nice to Have(建议优化)
  • 具体改进方案(添加参数化、断言实际行为、提取夹具等)
总结覆盖缺口:未测试的模块、缺失的边缘案例、无测试的集成点。

Reference — Test Design & Quality

参考——测试设计与质量

  • Overall test structure and organization
  • Adherence to testing best practices for the framework used
  • Alignment with SOLID and DRY principles
  • 整体测试结构与组织
  • 是否遵循所用框架的测试最佳实践
  • 是否符合SOLID和DRY原则

Reference — Problem Areas

参考——问题领域

  • "Nothing burger" tests—tests that pass trivially or don't validate real behavior
  • Missing parametrization where similar cases are tested with copy-paste
  • Overly complex test code that's hard to maintain
  • Large test files that should be split into logical groupings
  • “无意义”测试——轻易通过或未验证实际行为的测试
  • 相似案例通过复制粘贴测试、缺失参数化的情况
  • 过于复杂、难以维护的测试代码
  • 应拆分为逻辑分组的大型测试文件

Reference — Test Hygiene

参考——测试规范

  • Test isolation—do tests have side effects or depend on execution order?
  • Flaky tests—tests that pass/fail inconsistently
  • Mocking practices—appropriate use vs. over-mocking that hides real bugs
  • Test naming—do names clearly describe the scenario and expected outcome?
  • Setup/teardown—duplicated fixtures that should be shared
  • Execution time—slow tests that could be optimized or parallelized
  • 测试隔离性——测试是否存在副作用或依赖执行顺序?
  • 不稳定测试(Flaky tests)——测试结果不一致的情况
  • Mocking实践——合理使用vs过度Mock隐藏真实Bug
  • 测试命名——名称是否清晰描述场景和预期结果?
  • 前置/后置处理(Setup/teardown)——应共享的重复夹具
  • 执行时间——可优化或并行化的慢测试

Reference — Coverage Gaps

参考——覆盖缺口

  • Edge cases and failure modes not adequately tested
  • Integration points lacking coverage
  • 未充分测试的边缘案例和故障模式
  • 缺乏覆盖的集成点