Test Levels Framework

Comprehensive guide for determining appropriate test levels (unit, integration, E2E) for different scenarios.

Test Level Decision Matrix

Unit Tests

When to use:

Characteristics:

Example scenarios:

unit_test:
  component: 'PriceCalculator'
  scenario: 'Calculate discount with multiple rules'
  justification: 'Complex business logic with multiple branches'
  mock_requirements: 'None - pure function'

Integration Tests

When to use:

Characteristics:

Example scenarios:

integration_test:
  components: ['UserService', 'AuthRepository']
  scenario: 'Create user with role assignment'
  justification: 'Critical data flow between service and persistence'
  test_environment: 'In-memory database'

End-to-End Tests

When to use:

Characteristics:

Example scenarios:

e2e_test:
  journey: 'Complete checkout process'
  scenario: 'User purchases with saved payment method'
  justification: 'Revenue-critical path requiring full validation'
  environment: 'Staging with test payment gateway'

Test Level Selection Rules

Favor Unit Tests When:

Favor Integration Tests When:

Favor E2E Tests When:

Anti-patterns to Avoid

Duplicate Coverage Guard

Before adding any test, check:

  1. Is this already tested at a lower level?
  2. Can a unit test cover this instead of integration?
  3. Can an integration test cover this instead of E2E?

Coverage overlap is only acceptable when:

Test Naming Conventions

Test ID Format

{EPIC}.{STORY}-{LEVEL}-{SEQ}

Examples: