← 返回
未分类 中文

Test Design

Test design and strategy skill for comprehensive testing. Use when: designing test cases, planning testing strategy, writing unit/integration/e2e tests, or i...
测试设计与策略技能,用于全面测试。适用于:设计测试用例、规划测试策略、编写单元/集成/端到端测试等。
sydpz sydpz 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 398
下载
💾 0
安装
1
版本
#latest

概述

Test Design Skill

A structured approach to designing tests that give confidence without excessive maintenance burden.

Core Philosophy

Test behavior, not implementation. Tests that couple to internal implementation details become fragile and refactor-resistant. Aim to test what the code does, not how it does it.

The best test is the one that fails when something breaks, and passes when everything works. Perfect coverage means nothing if tests don't catch real bugs.

Testing Pyramid

        ┌─────────┐
        │   E2E   │  ← Few, slow, high confidence
       ┌┴─────────┴┐
       │ Integration│ ← Some, medium speed
      ┌┴───────────┴┐
      │    Unit     │ ← Many, fast, granular
      └─────────────┘

Unit tests form the base — fast, isolated, cover individual functions.

Integration tests verify components work together.

E2E tests validate complete user journeys.

Test Case Design

Arrange-Act-Assert (AAA) Pattern

def test_withdraw_amount_exceeds_balance():
    # Arrange
    account = Account(balance=Decimal("100.00"))
    
    # Act
    result = account.withdraw(Decimal("150.00"))
    
    # Assert
    assert result.is_failed()
    assert account.balance == Decimal("100.00")  # unchanged

Given-When-Then (GWT) Pattern

Feature: Account Withdrawal

  Scenario: Withdrawal amount exceeds balance
    Given an account with balance $100
    When I withdraw $150
    Then the withdrawal is rejected
    And the balance remains $100

Test Categories

🔴 Happy Path Tests

  • Verify the main success scenario works
  • At least one per feature/function

🟡 Edge Case Tests

  • Boundary values (0, -1, max integer)
  • Empty/null inputs
  • Rare but possible conditions

🟡 Error Case Tests

  • Invalid inputs
  • Missing dependencies
  • Permission denied scenarios

🟢 Edge/Extreme Cases

  • Very large inputs
  • Very small inputs
  • Unicode/special characters
  • Concurrent access

Test Doubles (Mocks/Stubs/Fakes)

TypePurposeUse When
-------------------------
DummyFill parameter listsNever actually used
StubProvide predetermined responsesTest requires specific data
SpyRecord how something was calledVerify interactions
MockPre-programmed expectationsVerify behavior + interactions
FakeWorking implementation (simplified)Real impl too slow/complex

Rule: Prefer real objects over mocks when practical. Mocks hide integration problems.

Test Naming Convention

test_<unit>_<scenario>_<expected_result>

Examples:

  • test_user_create_with_valid_input_succeeds
  • test_user_create_with_duplicate_email_fails
  • test_order_cancel_after_shipment_refunds_full_amount

Coverage Targets

LayerTargetPurpose
------------------------
Unit70-80%Core business logic
Integration40-60%Key flows work together
E2ECritical paths onlyUser journeys

Note: Coverage is a guide, not a goal. 100% coverage with shallow tests is worse than 70% with meaningful assertions.

Test Execution

Unit Tests

Run frequently during development (every save).

# Go
go test ./...

# Python
pytest tests/unit/ -v

# TypeScript
npm test -- --coverage

Integration Tests

Run before PR, after unit tests pass.

# Start dependencies
docker-compose up -d

# Run integration suite
pytest tests/integration/ -v

E2E Tests

Run on CI against deployed environment.

# CI/CD pipeline
npm run test:e2e -- --specs=critical-paths

Test Data Management

Strategies

  1. Factories/Fixtures — Create test data on demand
  2. Seeded Data — Deterministic test datasets
  3. Randomized Data — Fuzz testing with random inputs
  4. Snapshot Testing — Verify serializable outputs

Best Practices

  • Tests should be independent (no shared state)
  • Each test should clean up after itself
  • Use meaningful data, not magic values
  • Avoid test interdependencies

File Structure

test-design/
├── SKILL.md
└── references/
    ├── test-case-templates.md
    ├── testing-pyramid.md
    ├── mocking-strategies.md
    ├── test-naming-conventions.md
    └── per-type/
        ├── unit-test-guide.md
        ├── integration-test-guide.md
        └── e2e-test-guide.md

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-03 09:11 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

AIDLC Bug Killer

sydpz
多Agent协作Bug修复工作流:SubAgent检测Bug,主Agent修复,ReviewAgent确认。适用于多Agent协同修复项目Bug的场景。
★ 0 📥 461

Code Review

sydpz
代码审查最佳实践与工作流技能。适用场景:审查拉取请求、执行同行代码审查、制定代码审查标准或改进...
★ 0 📥 463

AI-DLC

sydpz
AI驱动的开发生命周期(AI‑DLC)自适应工作流,适用于新项目启动、新功能开发、bug修复、重构、迁移等场景。
★ 0 📥 609