regression-testing

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Regression Testing

回归测试

<default_to_action> When verifying changes don't break existing functionality:
  1. ANALYZE what changed (git diff, impact analysis)
  2. SELECT tests based on change + risk (not everything)
  3. RUN in priority order (smoke → selective → full)
  4. OPTIMIZE execution (parallel, sharding)
  5. MONITOR suite health (flakiness, execution time)
Quick Regression Strategy:
  • Per-commit: Smoke + changed code tests (5-10 min)
  • Nightly: Extended regression (30-60 min)
  • Pre-release: Full regression (2-4 hours)
Critical Success Factors:
  • Smart selection catches 90% of regressions in 10% of time
  • Flaky tests waste more time than they save
  • Every production bug becomes a regression test </default_to_action>
<default_to_action> 在验证变更不会破坏现有功能时:
  1. 分析变更内容(git diff、影响分析)
  2. 根据变更+风险选择测试用例(无需全部执行)
  3. 按优先级顺序执行(冒烟测试 → 选择性测试 → 全量测试)
  4. 优化执行效率(并行执行、分片)
  5. 监控测试套件健康度(不稳定测试、执行时长)
快速回归测试策略:
  • 每次提交:冒烟测试 + 变更代码相关测试(5-10分钟)
  • 夜间:扩展回归测试(30-60分钟)
  • 预发布:全量回归测试(2-4小时)
关键成功因素:
  • 智能选择能在10%的时间内发现90%的回归问题
  • 不稳定测试(Flaky tests)浪费的时间远多于其价值
  • 每一个生产环境的Bug都要转化为回归测试用例 </default_to_action>

Quick Reference Card

快速参考卡片

When to Use

适用场景

  • After any code change
  • Before release
  • After dependency updates
  • After environment changes
  • 任何代码变更后
  • 发布前
  • 依赖更新后
  • 环境变更后

Regression Types

回归测试类型

TypeWhenScope
CorrectiveNo code changeFull suite
ProgressiveNew featuresExisting + new
SelectiveSpecific changesChanged + dependent
CompleteMajor refactorEverything
类型适用场景范围
Corrective(校正型)无代码变更全量套件
Progressive(递进型)新增功能现有功能 + 新功能
Selective(选择型)特定变更变更代码 + 依赖代码
Complete(全面型)重大重构全部内容

Test Selection Strategies

测试用例选择策略

StrategyHowReduction
Change-basedGit diff analysis70-90%
Risk-basedPriority by impact50-70%
HistoricalFrequently failing40-60%
Time-budgetFixed time windowVariable

策略方式测试量减少比例
Change-based(基于变更)Git diff分析70-90%
Risk-based(基于风险)按影响优先级选择50-70%
Historical(基于历史)频繁失败的用例40-60%
Time-budget(基于时间预算)固定时间窗口可变

Change-Based Test Selection

基于变更的测试用例选择

typescript
// Analyze changed files and select impacted tests
function selectTests(changedFiles: string[]): string[] {
  const testsToRun = new Set<string>();

  for (const file of changedFiles) {
    // Direct tests
    testsToRun.add(`${file.replace('.ts', '.test.ts')}`);

    // Dependent tests (via coverage mapping)
    const dependentTests = testCoverage[file] || [];
    dependentTests.forEach(t => testsToRun.add(t));
  }

  return Array.from(testsToRun);
}

// Example: payment.ts changed
// Runs: payment.test.ts, checkout.integration.test.ts, e2e/purchase.test.ts

typescript
// 分析变更文件并选择受影响的测试用例
function selectTests(changedFiles: string[]): string[] {
  const testsToRun = new Set<string>();

  for (const file of changedFiles) {
    // 直接相关的测试用例
    testsToRun.add(`${file.replace('.ts', '.test.ts')}`);

    // 依赖的测试用例(通过覆盖率映射)
    const dependentTests = testCoverage[file] || [];
    dependentTests.forEach(t => testsToRun.add(t));
  }

  return Array.from(testsToRun);
}

// 示例:payment.ts 文件变更
// 执行:payment.test.ts, checkout.integration.test.ts, e2e/purchase.test.ts

Regression Suite Pyramid

回归测试套件金字塔

         /\
        /  \  Full Regression (weekly)
       /    \  - All tests (2-4 hours)
      /------\
     /        \  Extended Regression (nightly)
    /          \  - Unit + integration + critical E2E (30-60 min)
   /------------\
  /              \  Quick Regression (per commit)
 /________________\  - Changed code + smoke tests (5-10 min)

         /\
        /  \ 全量回归测试(每周)
       /    \  - 所有测试用例(2-4小时)
      /------\
     /        \ 扩展回归测试(夜间)
    /          \  - 单元测试 + 集成测试 + 关键端到端测试(30-60分钟)
   /------------\
  /              \ 快速回归测试(每次提交)
 /________________\  - 变更代码相关测试 + 冒烟测试(5-10分钟)

CI/CD Integration

CI/CD集成

yaml
undefined
yaml
undefined

.github/workflows/regression.yml

.github/workflows/regression.yml

jobs: quick-regression: runs-on: ubuntu-latest timeout-minutes: 15 steps: - name: Analyze changes id: changes uses: dorny/paths-filter@v2 with: filters: | payment: - 'src/payment/' auth: - 'src/auth/'
  - name: Run affected tests
    run: npm run test:affected

  - name: Smoke tests (always)
    run: npm run test:smoke
nightly-regression: if: github.event_name == 'schedule' timeout-minutes: 120 steps: - run: npm test -- --coverage

---
jobs: quick-regression: runs-on: ubuntu-latest timeout-minutes: 15 steps: - name: Analyze changes id: changes uses: dorny/paths-filter@v2 with: filters: | payment: - 'src/payment/' auth: - 'src/auth/'
  - name: Run affected tests
    run: npm run test:affected

  - name: Smoke tests (always)
    run: npm run test:smoke
nightly-regression: if: github.event_name == 'schedule' timeout-minutes: 120 steps: - run: npm test -- --coverage

---

Optimization Techniques

优化技巧

javascript
// 1. Parallel execution
module.exports = {
  maxWorkers: '50%', // Use half CPU cores
  testTimeout: 30000
};

// 2. Sharding across CI workers
// npm test -- --shard=1/4

// 3. Incremental testing (only changed since last run)
// Track last run state, skip passing unchanged tests

// 4. Fast-fail on smoke
// Run critical tests first, abort if they fail

javascript
// 1. 并行执行
module.exports = {
  maxWorkers: '50%', // 使用一半的CPU核心
  testTimeout: 30000
};

// 2. 在CI工作节点间分片执行
// npm test -- --shard=1/4

// 3. 增量测试(仅执行自上次运行后变更的内容)
// 跟踪上次运行状态,跳过未变更且通过的测试用例

// 4. 冒烟测试快速失败
// 先执行关键测试用例,若失败则终止执行

Agent-Driven Regression

Agent驱动的回归测试

typescript
// Smart test selection
await Task("Regression Analysis", {
  pr: 1234,
  strategy: 'change-based-with-risk',
  timeBudget: '15min'
}, "qe-regression-risk-analyzer");

// Returns:
// {
//   mustRun: ['payment.test.ts', 'checkout.integration.test.ts'],
//   shouldRun: ['order.test.ts'],
//   canSkip: ['profile.test.ts', 'search.test.ts'],
//   estimatedTime: '12 min',
//   riskCoverage: 0.94
// }

// Generate regression test from production bug
await Task("Bug Regression Test", {
  bug: { id: 'BUG-567', description: 'Checkout fails > 100 items' },
  preventRecurrence: true
}, "qe-test-generator");

typescript
// 智能测试用例选择
await Task("Regression Analysis", {
  pr: 1234,
  strategy: 'change-based-with-risk',
  timeBudget: '15min'
}, "qe-regression-risk-analyzer");

// 返回结果:
// {
//   mustRun: ['payment.test.ts', 'checkout.integration.test.ts'],
//   shouldRun: ['order.test.ts'],
//   canSkip: ['profile.test.ts', 'search.test.ts'],
//   estimatedTime: '12 min',
//   riskCoverage: 0.94
// }

// 从生产环境Bug生成回归测试用例
await Task("Bug Regression Test", {
  bug: { id: 'BUG-567', description: 'Checkout fails > 100 items' },
  preventRecurrence: true
}, "qe-test-generator");

Agent Coordination Hints

Agent协作提示

Memory Namespace

内存命名空间

aqe/regression-testing/
├── test-selection/*     - Impact analysis results
├── suite-health/*       - Flakiness, timing trends
├── coverage-maps/*      - Test-to-code mapping
└── bug-regressions/*    - Tests from production bugs
aqe/regression-testing/
├── test-selection/*     - 影响分析结果
├── suite-health/*       - 不稳定测试、时长趋势
├── coverage-maps/*      - 测试用例到代码的映射
└── bug-regressions/*    - 来自生产环境Bug的测试用例

Fleet Coordination

集群协作

typescript
const regressionFleet = await FleetManager.coordinate({
  strategy: 'comprehensive-regression',
  agents: [
    'qe-regression-risk-analyzer',  // Analyze changes, select tests
    'qe-test-executor',             // Execute selected tests
    'qe-coverage-analyzer',         // Analyze coverage gaps
    'qe-quality-gate'               // Go/no-go decision
  ],
  topology: 'sequential'
});

typescript
const regressionFleet = await FleetManager.coordinate({
  strategy: 'comprehensive-regression',
  agents: [
    'qe-regression-risk-analyzer',  // 分析变更,选择测试用例
    'qe-test-executor',             // 执行选中的测试用例
    'qe-coverage-analyzer',         // 分析覆盖率缺口
    'qe-quality-gate'               // 准入/准出决策
  ],
  topology: 'sequential'
});

Related Skills

相关技能

  • risk-based-testing - Risk-based prioritization
  • test-automation-strategy - Automation pyramid
  • continuous-testing-shift-left - CI/CD integration

  • risk-based-testing - 基于风险的优先级排序
  • test-automation-strategy - 自动化测试金字塔
  • continuous-testing-shift-left - CI/CD集成

Remember

要点提示

Regression testing is insurance against change. Every code change is a risk. Smart regression testing mitigates that risk by testing what matters based on what changed.
Good regression testing is strategic, not exhaustive. You cannot test everything, every time. Select based on changes, risk, and time budget.
With Agents:
qe-regression-risk-analyzer
provides intelligent test selection achieving 90% defect detection in 10% of execution time. Agents generate regression tests from production bugs automatically.
回归测试是应对变更的保障。 每一次代码变更都伴随着风险。智能回归测试通过基于变更内容测试关键部分来降低这种风险。
优秀的回归测试是策略性的,而非面面俱到的。 你不可能每次都测试所有内容。要根据变更、风险和时间预算来选择测试用例。
借助Agent:
qe-regression-risk-analyzer
提供智能测试用例选择,能在10%的执行时间内检测出90%的缺陷。Agent还能自动从生产环境Bug生成回归测试用例。