SuperAPI AI Directory

regression-testing

Testing & quality

View repository

Updated 10-16 09:30

About this skill

Regression Testing

References: ISTQB Foundation, Google "Software Engineering at Google" Test Selection, Microsoft Test Impact Analysis.

Applicable Scenarios

  • Regression before version release
  • Verify after Bug fix that no new problems are introduced
  • Verify unchanged behavior after refactoring / architecture adjustment
  • Dependency upgrades (library / framework / database version)
  • Configuration changes (environment / gateway / cache)

Core Principles

1. 不重复发生的 Bug 才是好回归
   每个修复的 Bug 必须有回归用例
  1. Regression is not running everything Do impact analysis and select suites based on the scope of change

  2. Three-tier suite structure Smoke / Sanity / Full (see below for details)

  3. Suites must be pruned Only stable if failure rate < 5% Those that have not failed for half a year may need to be deleted (or archived)

  4. Automation is the destination of regression Manual regression is unsustainable


## 三层套件结构

```text
┌─────────────────────────────────────┐
│ Smoke(5 分钟)                      │
│ - CI 每次必跑                        │
│ - 核心路径"能用"验证                 │
│ - 失败 = 阻塞合并                    │
└─────────────────────────────────────┘
┌─────────────────────────────────────┐
│ Sanity(30 分钟)                    │
│ - 发布前 / 每日定时跑                 │
│ - 主要功能正确性验证                  │
│ - 失败 = 阻塞发布                    │
└─────────────────────────────────────┘
┌─────────────────────────────────────┐
│ Full(1~3 小时)                     │
│ - 重大版本 / 重构后跑                 │
│ - 全量回归                           │
│ - 失败 = 评估影响后决策              │
└─────────────────────────────────────┘

Impact Analysis

1. 变更内容是什么?
   - 新增功能
   - 修改逻辑
   - 修复 Bug
   - 重构(行为应不变)
   - 依赖升级

2. 变更影响哪些代码?
   - 直接修改的模块
   - 调用方(谁用了它)
   - 被调用方(它用了谁)
   - 共享代码(utils、middleware)

3. 变更影响哪些功能?
   - 直接相关的用户流程
   - 间接相关(共享数据 / 状态 / 配置)

4. 选择回归套件
   - Smoke:必跑
   - Sanity:相关模块
   - Full:跨模块大改 / 重构

Impact Level Table

Change Type Recommended Regression
Bug fix (single point) Smoke + historical test cases for that Bug
Feature modification (single module) Smoke + Sanity (that module)
Cross-module feature Smoke + Sanity (involved modules)
Shared code change (utils) Smoke + Sanity (all modules)
Refactoring (behavior unchanged) Full
Database migration Full + data integrity special
Dependency upgrade (major) Full
Configuration change Affected scenarios + Smoke

Conversion of Bug → regression test case

Bug 修复后必做:

1. 写一条复现用例(最小复现路径)
2. 写一条边界用例(防类似变体)
3. 加入 Sanity 套件
4. 标注:源自 Bug-XXX
5. 6 个月内不删除

Example:

Bug-789:退款金额可输入负数

→ 回归用例 1:输入 -100,预期返回 INVALID_AMOUNT,金额无变化
→ 回归用例 2:输入 0,预期返回 INVALID_AMOUNT
→ 回归用例 3:输入超过订单金额的正数,预期返回 EXCEED_LIMIT
→ 回归用例 4:边界:等于订单金额(应该成功)

Suite Maintenance (Pruning)

Timing Action
Failure rate > 5% Fix or isolate Flaky test cases
No failure for 6 months Review, may need to delete
Module decommissioned Delete related test cases
Business change Update in sync
Test case execution > 5 minutes Split or optimize

Workflow

1. 收集变更说明
   - 修改了什么 / 为什么 / 影响范围
   ↓
2. 影响分析
   - 用变更范围决定回归层级
   ↓
3. 选择套件
   - Smoke / Sanity / Full
   ↓
4. 添加新用例(如有 Bug 修复)
   - 历史 Bug 转回归用例
   ↓
5. 执行(优先自动化)
   - 失败 → bug-reporting
   ↓
6. 失败分析
   - 真 Bug:开发修
   - Flaky:隔离 / 修复
   - 测试代码问题:修测试
   ↓
7. 报告
   - 通过率 / 失败用例 / 是否阻塞
   ↓
8. 套件维护
   - 加新用例 / 删旧用例 / 修 Flaky

Automation Strategy

高优先(必自动化):
  - Smoke 套件 100%
  - Sanity 套件 80%+
  - 历史 Bug 回归用例

中优先(可自动化):
  - Full 套件中稳定部分
  - API 契约测试

低优先(保留手工):
  - UI 视觉回归
  - 兼容性(多浏览器 / 设备)
  - 探索式

Flaky Test Case Handling

症状:用例时通过时失败,无规律

排查顺序:
  1. 时序:异步等待不够
  2. 数据:上一个用例污染
  3. 状态:缓存 / 会话残留
  4. 环境:网络 / 第三方抖动
  5. 并发:多线程 / 多用户冲突
  6. 时间:依赖具体日期 / 时区

处理:
  - 立即隔离(标 @flaky 跳过 CI)
  - 1 周内修复或删除
  - 不要"多重试几次让它过"

Quality Self-check

□ 三层套件清晰(Smoke/Sanity/Full)
□ Smoke < 5 min,Sanity < 30 min
□ 历史 Bug 100% 转回归用例
□ 失败率 < 5%
□ Flaky 用例已隔离或修复
□ 影响分析驱动套件选择
□ 重构后跑 Full
□ 6 个月未失败的用例已审视
□ 自动化优先级合理

Common Pitfalls

  1. Bug fixed without adding regression test cases——the same Bug recurs repeatedly
  2. Regression not tiered——runs for 3 hours every time, CI gets stuck
  3. No impact analysis——run everything or select randomly
  4. Flaky test cases rely on retries——masks real problems
  5. No maintenance for half a year——suite becomes bloated, new test cases are drowned out
  6. Manual regression depends on people——unsustainable, high omission rate
  7. Refactoring without running Full——assume "behavior unchanged", but actually break it
  8. Regression suite failure rate >> real Bug rate——a problem with the test cases themselves
  9. Deleting test cases without review——Important use cases were accidentally deleted
  10. Smoke runs are too heavy——Poor CI experience, unwilling to run

Supporting templates

  • templates/regression-suite-template.md — Three-layer suite + impact analysis + historical bug tracking + suite health self-check

Collaboration with other skills

上游:
  test-case-design → 提供用例
  bug-reporting → 历史 Bug
  risk-based-testing → 高风险点入回归

下游:
  自动化测试工作流 → 实现自动化套件
  quality-gate → 回归通过率作为门禁
  test-report → 回归结果纳入报告