shift-left-testing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseShift-Left Testing
左移测试
<default_to_action>
When implementing early testing practices:
- VALIDATE requirements before coding (testability, BDD scenarios)
- WRITE tests before implementation (TDD red-green-refactor)
- AUTOMATE in CI pipeline (every commit triggers tests)
- FOLLOW test pyramid: Many unit (70%), some integration (20%), few E2E (10%)
- FIX defects immediately - never let them accumulate
Quick Shift-Left Levels:
- Level 1: Unit tests with each PR (developer responsibility)
- Level 2: TDD practice (tests before code)
- Level 3: BDD/Example mapping in refinement (requirements testing)
- Level 4: Risk analysis in design (architecture testing)
Critical Success Factors:
- Defects found in requirements cost 1x; in production cost 100x
- Every commit must run automated tests
- Quality is built in, not tested in </default_to_action>
<default_to_action>
在实施早期测试实践时:
- 在编码前验证需求(可测试性、BDD场景)
- 在实现前编写测试(TDD红-绿-重构流程)
- 在CI流水线中实现自动化(每次提交触发测试)
- 遵循测试金字塔:大量单元测试(70%)、部分集成测试(20%)、少量端到端测试(10%)
- 立即修复缺陷——绝不让缺陷累积
快速了解左移测试层级:
- 层级1:每个PR附带单元测试(开发者负责)
- 层级2:践行TDD实践(先写测试再编码)
- 层级3:在需求细化阶段使用BDD/示例映射(需求测试)
- 层级4:在设计阶段进行风险分析(架构测试)
关键成功因素:
- 需求阶段发现的缺陷修复成本为1倍;生产环境发现的缺陷修复成本为100倍
- 每次提交必须运行自动化测试
- 质量是内置的,而非事后测试出来的 </default_to_action>
Quick Reference Card
快速参考卡片
When to Use
适用场景
- Reducing cost of defects
- Implementing CI/CD pipelines
- Starting TDD practice
- Improving requirements quality
- 降低缺陷修复成本
- 实施CI/CD流水线
- 开始践行TDD实践
- 提升需求质量
Cost of Defects by Phase
各阶段缺陷修复成本
| Phase | Relative Cost | Example |
|---|---|---|
| Requirements | 1x | Fix doc: 30 min |
| Design | 5x | Redesign: few hours |
| Development | 10x | Code fix: 1 day |
| Testing | 20x | Fix + retest: 2 days |
| Production | 100x | Hotfix + rollback + investigation |
| 阶段 | 相对成本 | 示例 |
|---|---|---|
| 需求阶段 | 1x | 修复文档:30分钟 |
| 设计阶段 | 5x | 重新设计:数小时 |
| 开发阶段 | 10x | 代码修复:1天 |
| 测试阶段 | 20x | 修复+重新测试:2天 |
| 生产环境 | 100x | 热修复+回滚+问题调查 |
Test Pyramid
测试金字塔
/\ E2E (10%) - Critical user journeys
/ \
/ \ Integration (20%) - Component interactions
/ \
/________\ Unit (70%) - Fast, isolated, comprehensive /\ E2E (10%) - 关键用户流程
/ \
/ \ 集成测试 (20%) - 组件交互
/ \
/________\ 单元测试 (70%) - 快速、隔离、全面Shift-Left Levels
左移测试层级
| Level | Practice | When |
|---|---|---|
| 1 | Unit tests in PR | Before merge |
| 2 | TDD | Before implementation |
| 3 | BDD/Example Mapping | During refinement |
| 4 | Risk Analysis | During design |
| 层级 | 实践内容 | 实施时机 |
|---|---|---|
| 1 | PR中包含单元测试 | 合并前 |
| 2 | TDD实践 | 代码实现前 |
| 3 | BDD/示例映射 | 需求细化阶段 |
| 4 | 风险分析 | 设计阶段 |
Level 1: Tests in Every PR
层级1:每个PR都包含测试
yaml
undefinedyaml
undefinedCI pipeline - tests run on every commit
CI pipeline - tests run on every commit
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run test:unit
- run: npm run test:integration
- run: npm run lint
quality-gate:
needs: test
steps:
- name: Coverage Check
run: npx coverage-check --min 80
- name: No New Warnings
run: npm run lint -- --max-warnings 0
---name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run test:unit
- run: npm run test:integration
- run: npm run lint
quality-gate:
needs: test
steps:
- name: Coverage Check
run: npx coverage-check --min 80
- name: No New Warnings
run: npm run lint -- --max-warnings 0
---Level 2: TDD Practice
层级2:TDD实践
javascript
// Red: Write failing test first
test('calculates discount for orders over $100', () => {
const order = new Order([{ price: 150 }]);
expect(order.discount).toBe(15); // 10% off
});
// Green: Minimal implementation
class Order {
get discount() {
return this.total > 100 ? this.total * 0.1 : 0;
}
}
// Refactor: Improve while keeping greenjavascript
// Red: Write failing test first
test('calculates discount for orders over $100', () => {
const order = new Order([{ price: 150 }]);
expect(order.discount).toBe(15); // 10% off
});
// Green: Minimal implementation
class Order {
get discount() {
return this.total > 100 ? this.total * 0.1 : 0;
}
}
// Refactor: Improve while keeping greenLevel 3: BDD in Refinement
层级3:需求细化阶段的BDD实践
gherkin
undefinedgherkin
undefinedExample mapping before coding
Example mapping before coding
Feature: Loyalty Discount
Scenario: Gold member gets 15% discount
Given a customer with "gold" membership
When they checkout with $200 in cart
Then discount applied is $30
And order total is $170
Scenario: New customer gets no discount
Given a customer with no membership
When they checkout with $200 in cart
Then no discount is applied
---Feature: Loyalty Discount
Scenario: Gold member gets 15% discount
Given a customer with "gold" membership
When they checkout with $200 in cart
Then discount applied is $30
And order total is $170
Scenario: New customer gets no discount
Given a customer with no membership
When they checkout with $200 in cart
Then no discount is applied
---Level 4: Risk Analysis in Design
层级4:设计阶段的风险分析
typescript
// During architecture review
await Task("Risk Analysis", {
phase: 'design',
component: 'payment-service',
questions: [
'What happens when payment gateway times out?',
'How do we handle duplicate submissions?',
'What if inventory changed during checkout?'
]
}, "qe-requirements-validator");
// Output: Testability requirements, failure mode teststypescript
// During architecture review
await Task("Risk Analysis", {
phase: 'design',
component: 'payment-service',
questions: [
'What happens when payment gateway times out?',
'How do we handle duplicate submissions?',
'What if inventory changed during checkout?'
]
}, "qe-requirements-validator");
// Output: Testability requirements, failure mode testsAgent-Assisted Shift-Left
Agent辅助的左移测试
typescript
// Validate requirements testability
await Task("Requirements Validation", {
requirements: userStories,
check: ['INVEST-criteria', 'testability', 'ambiguity'],
generateBDD: true
}, "qe-requirements-validator");
// Generate tests from requirements
await Task("Generate Tests", {
source: 'requirements',
types: ['unit', 'integration', 'e2e'],
coverage: 'comprehensive'
}, "qe-test-generator");
// Smart test selection for changes
await Task("Select Regression Tests", {
changedFiles: prFiles,
algorithm: 'risk-based',
targetReduction: 0.7 // 70% time savings
}, "qe-regression-risk-analyzer");typescript
// Validate requirements testability
await Task("Requirements Validation", {
requirements: userStories,
check: ['INVEST-criteria', 'testability', 'ambiguity'],
generateBDD: true
}, "qe-requirements-validator");
// Generate tests from requirements
await Task("Generate Tests", {
source: 'requirements',
types: ['unit', 'integration', 'e2e'],
coverage: 'comprehensive'
}, "qe-test-generator");
// Smart test selection for changes
await Task("Select Regression Tests", {
changedFiles: prFiles,
algorithm: 'risk-based',
targetReduction: 0.7 // 70% time savings
}, "qe-regression-risk-analyzer");Agent Coordination Hints
Agent协作提示
Memory Namespace
内存命名空间
aqe/shift-left/
├── requirements/* - Validated requirements
├── generated-tests/* - Auto-generated tests
├── coverage-targets/* - Coverage goals by component
└── pipeline-results/* - CI/CD test historyaqe/shift-left/
├── requirements/* - Validated requirements
├── generated-tests/* - Auto-generated tests
├── coverage-targets/* - Coverage goals by component
└── pipeline-results/* - CI/CD test historyFleet Coordination
集群协作
typescript
const shiftLeftFleet = await FleetManager.coordinate({
strategy: 'shift-left',
agents: [
'qe-requirements-validator', // Level 3-4
'qe-test-generator', // Level 2
'qe-regression-risk-analyzer' // Smart selection
],
topology: 'sequential'
});typescript
const shiftLeftFleet = await FleetManager.coordinate({
strategy: 'shift-left',
agents: [
'qe-requirements-validator', // Level 3-4
'qe-test-generator', // Level 2
'qe-regression-risk-analyzer' // Smart selection
],
topology: 'sequential'
});Related Skills
相关技能
- tdd-london-chicago - TDD practices
- holistic-testing-pact - Proactive testing
- cicd-pipeline-qe-orchestrator - Pipeline integration
- shift-right-testing - Production feedback
- tdd-london-chicago - TDD practices
- holistic-testing-pact - Proactive testing
- cicd-pipeline-qe-orchestrator - Pipeline integration
- shift-right-testing - Production feedback
Remember
要点回顾
Earlier = Cheaper. Requirements defects cost 1x; production defects cost 100x. Test pyramid: 70% unit, 20% integration, 10% E2E. Every commit runs tests. TDD builds quality in.
With Agents: Agents validate requirements testability, generate tests from specs, and select optimal regression suites. Use agents to implement shift-left practices consistently.
越早发现,成本越低。 需求阶段的缺陷修复成本为1倍;生产环境的缺陷修复成本为100倍。测试金字塔:70%单元测试、20%集成测试、10%E2E测试。每次提交都要运行测试。TDD将质量内置到开发过程中。
借助Agent: Agent可验证需求的可测试性、根据需求生成测试、选择最优回归测试套件。使用Agent可确保左移测试实践的一致性落地。