test-design-techniques

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Test Design Techniques

测试设计技术

<default_to_action> When designing test cases systematically:
  1. APPLY Boundary Value Analysis (test at min, max, edges)
  2. USE Equivalence Partitioning (one test per partition)
  3. CREATE Decision Tables (for complex business rules)
  4. MODEL State Transitions (for stateful behavior)
  5. REDUCE with Pairwise Testing (for combinations)
Quick Design Selection:
  • Numeric ranges → BVA + EP
  • Multiple conditions → Decision Tables
  • Workflows → State Transition
  • Many parameters → Pairwise Testing
Critical Success Factors:
  • Systematic design finds more bugs with fewer tests
  • Random testing is inefficient
  • 40+ years of research backs these techniques </default_to_action>
<default_to_action> 当系统化设计测试用例时:
  1. 应用边界值分析(Boundary Value Analysis,BVA)(在最小值、最大值、边界点进行测试)
  2. 使用等价类划分(Equivalence Partitioning,EP)(每个划分仅需一个测试用例)
  3. 创建决策表(用于复杂业务规则)
  4. 建模状态转换(针对有状态行为)
  5. 通过成对测试(Pairwise Testing)减少测试量(针对多参数组合)
快速设计选择:
  • 数值范围 → BVA + EP
  • 多条件场景 → 决策表
  • 工作流 → 状态转换测试
  • 多参数场景 → 成对测试
关键成功因素:
  • 系统化设计能用更少的测试用例发现更多Bug
  • 随机测试效率低下
  • 这些技术拥有40余年的研究支撑 </default_to_action>

Quick Reference Card

快速参考卡片

When to Use

适用场景

  • Designing new test suites
  • Optimizing existing tests
  • Complex business rules
  • Reducing test redundancy
  • 设计新测试套件
  • 优化现有测试用例
  • 复杂业务规则场景
  • 减少测试冗余

Technique Selection Guide

技术选择指南

ScenarioTechnique
Numeric input rangesBVA + EP
Multiple conditionsDecision Tables
Stateful workflowsState Transition
Many parameter combinationsPairwise
All combinations criticalFull Factorial

场景技术
数值输入范围BVA + EP
多条件组合决策表
有状态工作流状态转换测试
多参数组合成对测试
全组合至关重要全因子测试

Boundary Value Analysis (BVA)

边界值分析(BVA)

Principle: Bugs cluster at boundaries.
Test at boundaries:
  • Minimum valid value
  • Just below minimum (invalid)
  • Just above minimum (valid)
  • Maximum valid value
  • Just above maximum (invalid)
javascript
// Age field: 18-120 valid
const boundaryTests = [
  { input: 17, expected: 'invalid' },  // Below min
  { input: 18, expected: 'valid' },    // Min boundary
  { input: 19, expected: 'valid' },    // Above min
  { input: 119, expected: 'valid' },   // Below max
  { input: 120, expected: 'valid' },   // Max boundary
  { input: 121, expected: 'invalid' }  // Above max
];

核心原则: Bug集中出现在边界点。
测试边界点:
  • 最小有效值
  • 略低于最小值(无效)
  • 略高于最小值(有效)
  • 最大有效值
  • 略高于最大值(无效)
javascript
// Age field: 18-120 valid
const boundaryTests = [
  { input: 17, expected: 'invalid' },  // Below min
  { input: 18, expected: 'valid' },    // Min boundary
  { input: 19, expected: 'valid' },    // Above min
  { input: 119, expected: 'valid' },   // Below max
  { input: 120, expected: 'valid' },   // Max boundary
  { input: 121, expected: 'invalid' }  // Above max
];

Equivalence Partitioning (EP)

等价类划分(EP)

Principle: One test per equivalent class.
javascript
// Discount rules:
// 1-10:  No discount
// 11-100: 10% discount
// 101+:   20% discount

const partitionTests = [
  { quantity: -1, expected: 'invalid' },  // Invalid partition
  { quantity: 5, expected: 0 },           // Partition 1: 1-10
  { quantity: 50, expected: 0.10 },       // Partition 2: 11-100
  { quantity: 200, expected: 0.20 }       // Partition 3: 101+
];

// 4 tests cover all behavior (vs 200+ if testing every value)

核心原则: 每个等价类仅需一个测试用例。
javascript
// Discount rules:
// 1-10:  No discount
// 11-100: 10% discount
// 101+:   20% discount

const partitionTests = [
  { quantity: -1, expected: 'invalid' },  // Invalid partition
  { quantity: 5, expected: 0 },           // Partition 1: 1-10
  { quantity: 50, expected: 0.10 },       // Partition 2: 11-100
  { quantity: 200, expected: 0.20 }       // Partition 3: 101+
];

// 4个测试用例即可覆盖所有行为(若逐个值测试则需200+个)

Decision Tables

决策表

Use for: Complex business rules with multiple conditions.
Loan Approval Rules:
┌──────────────┬───────┬───────┬───────┬───────┬───────┐
│ Conditions   │ R1    │ R2    │ R3    │ R4    │ R5    │
├──────────────┼───────┼───────┼───────┼───────┼───────┤
│ Age ≥ 18     │ Yes   │ Yes   │ Yes   │ No    │ Yes   │
│ Credit ≥ 700 │ Yes   │ Yes   │ No    │ Yes   │ No    │
│ Income ≥ 50k │ Yes   │ No    │ Yes   │ Yes   │ Yes   │
├──────────────┼───────┼───────┼───────┼───────┼───────┤
│ Result       │Approve│Approve│Reject │Reject │Reject │
└──────────────┴───────┴───────┴───────┴───────┴───────┘

// 5 tests cover all decision combinations

适用场景: 包含多条件的复杂业务规则。
Loan Approval Rules:
┌──────────────┬───────┬───────┬───────┬───────┬───────┐
│ Conditions   │ R1    │ R2    │ R3    │ R4    │ R5    │
├──────────────┼───────┼───────┼───────┼───────┼───────┤
│ Age ≥ 18     │ Yes   │ Yes   │ Yes   │ No    │ Yes   │
│ Credit ≥ 700 │ Yes   │ Yes   │ No    │ Yes   │ No    │
│ Income ≥ 50k │ Yes   │ No    │ Yes   │ Yes   │ Yes   │
├──────────────┼───────┼───────┼───────┼───────┼───────┤
│ Result       │Approve│Approve│Reject │Reject │Reject │
└──────────────┴───────┴───────┴───────┴───────┴───────┘

// 5个测试用例即可覆盖所有决策组合

State Transition Testing

状态转换测试

Model state changes:
States: Logged Out → Logged In → Premium → Suspended

Valid Transitions:
- Login: Logged Out → Logged In
- Upgrade: Logged In → Premium
- Payment Fail: Premium → Suspended
- Logout: Any → Logged Out

Invalid Transitions to Test:
- Logged Out → Premium (should reject)
- Suspended → Premium (should reject)
javascript
test('cannot upgrade without login', async () => {
  const result = await user.upgrade(); // While logged out
  expect(result.error).toBe('Login required');
});

建模状态变化:
States: Logged Out → Logged In → Premium → Suspended

Valid Transitions:
- Login: Logged Out → Logged In
- Upgrade: Logged In → Premium
- Payment Fail: Premium → Suspended
- Logout: Any → Logged Out

Invalid Transitions to Test:
- Logged Out → Premium (should reject)
- Suspended → Premium (should reject)
javascript
test('cannot upgrade without login', async () => {
  const result = await user.upgrade(); // While logged out
  expect(result.error).toBe('Login required');
});

Pairwise (Combinatorial) Testing

成对(组合)测试

Problem: All combinations explode exponentially.
javascript
// Parameters:
// Browser: Chrome, Firefox, Safari (3)
// OS: Windows, Mac, Linux (3)
// Screen: Desktop, Tablet, Mobile (3)

// All combinations: 3 × 3 × 3 = 27 tests
// Pairwise: 9 tests cover all pairs

const pairwiseTests = [
  { browser: 'Chrome', os: 'Windows', screen: 'Desktop' },
  { browser: 'Chrome', os: 'Mac', screen: 'Tablet' },
  { browser: 'Chrome', os: 'Linux', screen: 'Mobile' },
  { browser: 'Firefox', os: 'Windows', screen: 'Tablet' },
  { browser: 'Firefox', os: 'Mac', screen: 'Mobile' },
  { browser: 'Firefox', os: 'Linux', screen: 'Desktop' },
  { browser: 'Safari', os: 'Windows', screen: 'Mobile' },
  { browser: 'Safari', os: 'Mac', screen: 'Desktop' },
  { browser: 'Safari', os: 'Linux', screen: 'Tablet' }
];
// Each pair appears at least once

问题: 全量参数组合会导致测试量呈指数级增长。
javascript
// Parameters:
// Browser: Chrome, Firefox, Safari (3)
// OS: Windows, Mac, Linux (3)
// Screen: Desktop, Tablet, Mobile (3)

// All combinations: 3 × 3 × 3 = 27 tests
// Pairwise: 9 tests cover all pairs

const pairwiseTests = [
  { browser: 'Chrome', os: 'Windows', screen: 'Desktop' },
  { browser: 'Chrome', os: 'Mac', screen: 'Tablet' },
  { browser: 'Chrome', os: 'Linux', screen: 'Mobile' },
  { browser: 'Firefox', os: 'Windows', screen: 'Tablet' },
  { browser: 'Firefox', os: 'Mac', screen: 'Mobile' },
  { browser: 'Firefox', os: 'Linux', screen: 'Desktop' },
  { browser: 'Safari', os: 'Windows', screen: 'Mobile' },
  { browser: 'Safari', os: 'Mac', screen: 'Desktop' },
  { browser: 'Safari', os: 'Linux', screen: 'Tablet' }
];
// 每对参数组合至少出现一次

Agent-Driven Test Design

Agent驱动的测试设计

typescript
// Auto-generate BVA tests
await Task("Generate BVA Tests", {
  field: 'age',
  dataType: 'integer',
  constraints: { min: 18, max: 120 }
}, "qe-test-generator");
// Returns: 6 boundary test cases

// Auto-generate pairwise tests
await Task("Generate Pairwise Tests", {
  parameters: {
    browser: ['Chrome', 'Firefox', 'Safari'],
    os: ['Windows', 'Mac', 'Linux'],
    screen: ['Desktop', 'Tablet', 'Mobile']
  }
}, "qe-test-generator");
// Returns: 9-12 tests (vs 27 full combination)

typescript
// 自动生成BVA测试用例
await Task("Generate BVA Tests", {
  field: 'age',
  dataType: 'integer',
  constraints: { min: 18, max: 120 }
}, "qe-test-generator");
// 返回:6个边界测试用例

// 自动生成成对测试用例
await Task("Generate Pairwise Tests", {
  parameters: {
    browser: ['Chrome', 'Firefox', 'Safari'],
    os: ['Windows', 'Mac', 'Linux'],
    screen: ['Desktop', 'Tablet', 'Mobile']
  }
}, "qe-test-generator");
// 返回:9-12个测试用例(对比全量组合的27个)

Agent Coordination Hints

Agent协作提示

Memory Namespace

内存命名空间

aqe/test-design/
├── bva-analysis/*       - Boundary value tests
├── partitions/*         - Equivalence partitions
├── decision-tables/*    - Decision table tests
└── pairwise/*           - Combinatorial reduction
aqe/test-design/
├── bva-analysis/*       - 边界值测试用例
├── partitions/*         - 等价类划分
├── decision-tables/*    - 决策表测试用例
└── pairwise/*           - 组合测试精简结果

Fleet Coordination

集群协作

typescript
const designFleet = await FleetManager.coordinate({
  strategy: 'systematic-test-design',
  agents: [
    'qe-test-generator',    // Apply design techniques
    'qe-coverage-analyzer', // Analyze coverage
    'qe-quality-analyzer'   // Assess test quality
  ],
  topology: 'sequential'
});

typescript
const designFleet = await FleetManager.coordinate({
  strategy: 'systematic-test-design',
  agents: [
    'qe-test-generator',    // 应用测试设计技术
    'qe-coverage-analyzer', // 分析测试覆盖度
    'qe-quality-analyzer'   // 评估测试质量
  ],
  topology: 'sequential'
});

Related Skills

相关技能

  • agentic-quality-engineering - Agent-driven testing
  • risk-based-testing - Prioritize by risk
  • mutation-testing - Validate test effectiveness

  • agentic-quality-engineering - Agent驱动的测试
  • risk-based-testing - 基于风险的测试优先级划分
  • mutation-testing - 验证测试有效性

Remember

要点回顾

Systematic design > Random testing. 40+ years of research shows these techniques find more bugs with fewer tests than ad-hoc approaches.
Combine techniques for comprehensive coverage. BVA for boundaries, EP for partitions, decision tables for rules, pairwise for combinations.
With Agents:
qe-test-generator
applies these techniques automatically, generating optimal test suites with maximum coverage and minimum redundancy. Agents identify boundaries, partitions, and combinations from code analysis.
系统化设计 > 随机测试。40余年的研究表明,与临时测试方法相比,这些技术能用更少的测试用例发现更多Bug。
组合多种技术实现全面覆盖。用BVA覆盖边界、EP覆盖等价类、决策表覆盖规则、成对测试覆盖多参数组合。
借助Agent:
qe-test-generator
可自动应用这些技术,生成覆盖范围最大、冗余度最低的最优测试套件。Agent能通过代码分析识别边界、等价类和参数组合。