qa-testing-strategy

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

QA Testing Strategy (Jan 2026)

QA测试策略(2026年1月)

Risk-based quality engineering strategy for modern software delivery.
Core references: curated links in
data/sources.json
(SLOs/error budgets, contracts, E2E, OpenTelemetry). Start with
references/operational-playbook.md
for a compact, navigable overview.
面向现代软件交付的基于风险的质量工程策略。
核心参考资料
data/sources.json
中整理的链接(SLO/错误预算、契约、E2E、OpenTelemetry)。可先查看
references/operational-playbook.md
获取简洁的导航式概述。

Scope

适用范围

  • Create or update a risk-based test strategy (what to test, where, and why)
  • Define quality gates and release criteria (merge vs deploy)
  • Select the smallest effective layer (unit → integration → contract → E2E)
  • Make failures diagnosable (artifacts, logs/traces, ownership)
  • Operationalize reliability (flake SLO, quarantines, suite budgets)
  • 创建或更新基于风险的测试策略(测试内容、测试场景及原因)
  • 定义质量门禁和发布标准(合并代码 vs 部署上线的要求)
  • 选择最有效的测试层级(单元→集成→契约→E2E)
  • 确保故障可诊断(提供制品、日志/链路追踪、明确责任人)
  • 落地可靠性管理(不稳定测试SLO、隔离机制、测试套件预算)

Use Instead

替代方案

NeedSkill
Debug failing tests or incidentsqa-debugging
Test LLM agents/personasqa-agent-testing
Perform security audit/threat modelsoftware-security-appsec
Design CI/CD pipelines and infraops-devops-platform
需求场景对应技能
调试失败的测试或事件qa-debugging
测试LLM Agent/角色qa-agent-testing
执行安全审计/威胁建模software-security-appsec
设计CI/CD流水线和基础设施ops-devops-platform

Quick Reference

速查参考

Test TypeGoalTypical Use
UnitProve logic and invariants fastPure functions, core business rules
ComponentValidate UI behavior in isolationUI components and state transitions
IntegrationValidate boundaries with real depsAPI + DB, queues, external adapters
ContractPrevent breaking changes cross-teamOpenAPI/AsyncAPI/JSON Schema/Protobuf
E2EValidate critical user journeys1–2 “money paths” per product area
PerformanceEnforce budgets and capacityLoad, stress, soak, regression trends
VisualCatch UI regressionsLayout/visual diffs on stable pages
AccessibilityAutomate WCAG checksaxe smoke + targeted manual audits
SecurityCatch common web vulns earlyDAST smoke + critical checks in CI
测试类型目标典型场景
单元测试快速验证逻辑和不变量纯函数、核心业务规则
组件测试隔离验证UI行为UI组件和状态转换
集成测试验证与真实依赖的边界交互API+数据库、消息队列、外部适配器
契约测试跨团队防止破坏性变更OpenAPI/AsyncAPI/JSON Schema/Protobuf
E2E测试验证关键用户路径每个产品域1-2条“核心业务路径”
性能测试执行预算和容量验证负载、压力、稳定性、回归趋势测试
视觉测试捕获UI回归问题稳定页面的布局/视觉差异对比
可访问性测试自动化WCAG合规检查axe工具快速扫描+针对性人工审计
安全测试尽早发现常见Web漏洞DAST快速扫描+CI中执行关键检查

Default Workflow

默认工作流

  1. Clarify scope and risk: critical journeys, failure modes, and non-functional risks (latency, data loss, auth).
  2. Define quality signals: SLOs/error budgets, contract/schema checks, and what blocks merge vs blocks deploy.
  3. Choose the smallest effective layer (unit → integration → contract → E2E).
  4. Make failures diagnosable: artifacts + correlation IDs (logs/traces/screenshots), clear ownership, deflake runbook.
  5. Operationalize: flake SLO, quarantine with expiry, suite budgets (PR gate vs scheduled), dashboards.
  1. 明确范围和风险:关键用户路径、故障模式、非功能性风险(延迟、数据丢失、认证)。
  2. 定义质量信号:SLO/错误预算、契约/ schema检查,区分代码合并和部署上线的阻塞条件。
  3. 选择最有效的测试层级(单元→集成→契约→E2E)。
  4. 确保故障可诊断:提供制品+关联ID(日志/链路追踪/截图)、明确责任人、不稳定测试排查手册。
  5. 落地执行:不稳定测试SLO、带过期时间的隔离机制、测试套件预算(PR门禁 vs 定时执行)、监控仪表盘。

Test Pyramid

测试金字塔

text
           /\
          /E2E\          5-10% - Critical journeys
         /------\
        /Integr. \       15-25% - API, DB, queues
       /----------\
      /Component \       20-30% - UI modules
     /------------\
    /   Unit      \      40-60% - Logic and invariants
   /--------------\
text
           /\
          /E2E\          5-10% - 关键用户路径
         /------\
        /Integr. \       15-25% - API、数据库、消息队列
       /----------\
      /Component \       20-30% - UI模块
     /------------\
    /   Unit      \      40-60% - 逻辑和不变量
   /--------------\

Decision Tree: Test Strategy

测试策略决策树

text
Need to test: [Feature Type]
    ├─ Pure business logic/invariants? → Unit tests (mock boundaries)
    ├─ UI component/state transitions? → Component tests
    │   └─ Cross-page user journey? → E2E tests
    ├─ API Endpoint?
    │   ├─ Single service boundary? → Integration tests (real DB/deps)
    │   └─ Cross-service compatibility? → Contract tests (schema/versioning)
    ├─ Event-driven/API schema evolution? → Contract + backward-compat tests
    └─ Performance-critical? → k6 load testing
text
需要测试:[功能类型]
    ├─ 纯业务逻辑/不变量?→ 单元测试(模拟依赖边界)
    ├─ UI组件/状态转换?→ 组件测试
    │   └─ 跨页面用户路径?→ E2E测试
    ├─ API接口?
    │   ├─ 单一服务边界?→ 集成测试(真实数据库/依赖)
    │   └─ 跨服务兼容性?→ 契约测试(Schema/版本管理)
    ├─ 事件驱动/API Schema演进?→ 契约测试+向后兼容测试
    └─ 性能关键型功能?→ k6负载测试

Core QA Principles

核心QA原则

Definition of Done

完成定义

  • Strategy is risk-based: critical journeys + failure modes explicit
  • Test portfolio is layered: fast checks catch most defects
  • CI is economical: fast pre-merge gates, heavy suites scheduled
  • Failures are diagnosable: actionable artifacts (logs/trace/screenshots)
  • Flakes managed with SLO and deflake runbook
  • 策略基于风险:明确关键用户路径和故障模式
  • 测试组合分层:快速检查捕获大多数缺陷
  • CI执行高效:预合并阶段快速门禁,重量级测试套件定时执行
  • 故障可诊断:提供可操作的制品(日志/链路追踪/截图)
  • 通过SLO和排查手册管理不稳定测试

Shift-Left Gates (Pre-Merge)

左移门禁(预合并阶段)

  • Contracts: OpenAPI/AsyncAPI/JSON Schema validation
  • Static checks: lint, typecheck, secret scanning
  • Fast tests: unit + key integration (avoid full E2E as PR gate)
  • 契约检查:OpenAPI/AsyncAPI/JSON Schema验证
  • 静态检查:代码规范、类型检查、敏感信息扫描
  • 快速测试:单元测试+核心集成测试(避免将完整E2E作为PR门禁)

Shift-Right (Post-Deploy)

右移验证(部署后阶段)

  • Synthetic checks for critical paths (monitoring-as-tests)
  • Canary analysis: compare SLO signals and key metrics before ramping
  • Feature flags for safe rollouts and fast rollback
  • Convert incidents into regression tests (prefer lower layers first)
  • 核心路径的合成监控(以监控为测试)
  • 金丝雀发布分析:扩容前对比SLO信号和关键指标
  • 功能灰度发布:安全上线与快速回滚
  • 将事件转化为回归测试(优先选择低层测试)

CI Economics

CI成本优化

BudgetTarget
PR gatep50 ≤ 10 min, p95 ≤ 20 min
Mainline health≥ 99% green builds/day
预算指标目标值
PR门禁p50 ≤ 10分钟,p95 ≤ 20分钟
主干分支健康度每日构建成功率 ≥ 99%

Flake Management

不稳定测试管理

  • Define: test fails without product change, passes on rerun
  • Track weekly:
    flaky_failures / total_test_executions
    (where
    flaky_failure = fail_then_pass_on_rerun
    )
  • SLO: Suite flake rate ≤ 1% weekly
  • Quarantine policy with owner and expiry
  • Use the deflake runbook: template-flaky-test-triage-deflake-runbook.md
  • 定义:无产品代码变更时测试失败,重新执行则通过
  • 每周追踪:
    不稳定测试失败数 / 总测试执行数
    (其中
    不稳定测试失败数
    =失败后重新执行通过的次数)
  • SLO:测试套件每周不稳定率 ≤ 1%
  • 带责任人与过期时间的隔离机制
  • 使用排查手册:template-flaky-test-triage-deflake-runbook.md

Common Patterns

常见模式

AAA Pattern

AAA模式

javascript
it('should apply discount', () => {
  // Arrange
  const order = { total: 150 };
  // Act
  const result = calculateDiscount(order);
  // Assert
  expect(result.discount).toBe(15);
});
javascript
it('should apply discount', () => {
  // Arrange
  const order = { total: 150 };
  // Act
  const result = calculateDiscount(order);
  // Assert
  expect(result.discount).toBe(15);
});

Page Object Model (E2E)

页面对象模型(E2E)

typescript
class LoginPage {
  async login(email: string, password: string) {
    await this.page.fill('[data-testid="email"]', email);
    await this.page.fill('[data-testid="password"]', password);
    await this.page.click('[data-testid="submit"]');
  }
}
typescript
class LoginPage {
  async login(email: string, password: string) {
    await this.page.fill('[data-testid="email"]', email);
    await this.page.fill('[data-testid="password"]', password);
    await this.page.click('[data-testid="submit"]');
  }
}

Anti-Patterns

反模式

Anti-PatternProblemSolution
Testing implementationBreaks on refactorTest behavior
Shared mutable stateFlaky testsIsolate test data
sleep() in testsSlow, unreliableUse proper waits
Everything E2ESlow, expensiveUse test pyramid
Ignoring flaky testsFalse confidenceFix or quarantine
反模式问题解决方案
测试实现细节重构时易失效测试行为而非实现
共享可变状态导致测试不稳定隔离测试数据
测试中使用sleep()缓慢且不可靠使用事件驱动的等待机制
所有测试都用E2E缓慢且成本高遵循测试金字塔原则
忽略不稳定测试导致虚假的信心修复或隔离不稳定测试

Do / Avoid

建议/禁忌

Do

建议

  • Write tests against stable contracts and user-visible behavior
  • Treat flaky tests as P1 reliability work
  • Make "how to debug this failure" part of every suite
  • 针对稳定契约和用户可见行为编写测试
  • 将不稳定测试视为P1可靠性任务
  • 为每个测试套件添加“如何调试此故障”的说明

Avoid

禁忌

  • "Everything E2E" as default
  • Sleeps/time-based waits (use event-based)
  • Coverage % as primary quality KPI
  • 默认使用“全E2E测试”
  • 使用sleep()/基于时间的等待(改用事件驱动等待)
  • 将覆盖率作为主要质量KPI

Resources

资源

ResourcePurpose
comprehensive-testing-guide.mdEnd-to-end playbook across layers
operational-playbook.mdTesting pyramid, BDD, CI gates
shift-left-testing.mdContract-first, BDD, continuous testing
test-automation-patterns.mdReliable patterns and anti-patterns
playwright-webapp-testing.mdPlaywright patterns
chaos-resilience-testing.mdChaos engineering
observability-driven-testing.mdOpenTelemetry, trace-based
contract-testing-2026.mdPact, Specmatic
synthetic-test-data.mdPrivacy-safe, ephemeral test data
资源用途
comprehensive-testing-guide.md跨测试层级的完整操作手册
operational-playbook.md测试金字塔、BDD、CI门禁
shift-left-testing.md契约优先、BDD、持续测试
test-automation-patterns.md可靠模式与反模式
playwright-webapp-testing.mdPlaywright使用模式
chaos-resilience-testing.md混沌工程
observability-driven-testing.mdOpenTelemetry、基于链路追踪的测试
contract-testing-2026.mdPact、Specmatic契约测试
synthetic-test-data.md隐私安全的临时测试数据

Templates

模板

TemplatePurpose
template-test-case-design.mdGiven/When/Then and test oracles
test-strategy-template.mdRisk-based strategy
template-flaky-test-triage.mdFlake triage runbook
template-jest-vitest.mdUnit test patterns
template-api-integration.mdAPI + DB integration tests
template-playwright.mdPlaywright E2E
template-visual-testing.mdVisual regression testing
template-k6-load-testing.mdk6 performance
automation-pipeline-template.mdCI stages, budgets, gates
template-cucumber-gherkin.mdBDD feature files and steps
模板用途
template-test-case-design.mdGiven/When/Then测试用例设计和测试断言
test-strategy-template.md基于风险的测试策略模板
template-flaky-test-triage.md不稳定测试排查手册模板
template-jest-vitest.md单元测试模式模板
template-api-integration.mdAPI+数据库集成测试模板
template-playwright.mdPlaywright E2E测试模板
template-visual-testing.md视觉回归测试模板
template-k6-load-testing.mdk6性能测试模板
automation-pipeline-template.mdCI阶段、预算、门禁模板
template-cucumber-gherkin.mdBDD特性文件和步骤模板

Data

数据文件

FilePurpose
sources.jsonExternal references
文件用途
sources.json外部参考链接集合

Related Skills

相关技能

  • qa-debugging — Debugging failing tests
  • qa-agent-testing — Testing AI agents
  • software-backend — API patterns to test
  • ops-devops-platform — CI/CD pipelines
  • qa-debugging — 调试失败的测试
  • qa-agent-testing — 测试AI Agent
  • software-backend — 待测试的API模式
  • ops-devops-platform — CI/CD流水线