---
name: testing-strategies
description: |
  Testing strategies and patterns for Claude Code workflows.
  Use when writing tests, designing test suites, or implementing
  TDD practices.

allowed-tools:
  - Bash
  - Read
  - Write
---

# Testing Strategies Skill

## Test Types

| Type | Purpose | Speed |
|------|---------|-------|
| Unit | Individual functions | Fast |
| Integration | Component interaction | Medium |
| E2E | Full workflow | Slow |
| Smoke | Critical paths | Fast |

## TDD Workflow

```
1. Write failing test
2. Write minimal code to pass
3. Refactor
4. Repeat
```

## Test Structure

### Arrange-Act-Assert

```python
def test_user_login():
    # Arrange
    user = create_test_user()
    
    # Act
    result = login(user.email, user.password)
    
    # Assert
    assert result.success == True
```

### Given-When-Then

```python
def test_order_discount():
    # Given a premium customer with cart over $100
    customer = Customer(tier="premium")
    cart = Cart(total=150)
    
    # When checkout is processed
    order = checkout(customer, cart)
    
    # Then 20% discount is applied
    assert order.discount == 30
```

## Test Coverage Goals

| Area | Target |
|------|--------|
| Critical paths | 100% |
| Business logic | 90%+ |
| Edge cases | Explicit |
| Error handling | All paths |

## Mocking Patterns

```python
from unittest.mock import Mock, patch

@patch('module.external_api')
def test_with_mock(mock_api):
    mock_api.return_value = {"status": "ok"}
    result = function_under_test()
    assert result == expected
```

## Claude Code Testing Commands

```bash
# Run tests
Bash("pytest tests/")

# With coverage
Bash("pytest --cov=src tests/")

# Specific test
Bash("pytest tests/test_auth.py::test_login")
```

## Genesis Testing Protocol

1. Black box tests (external behavior)
2. White box tests (internal paths)
3. All tests must pass
4. Document results

## Best Practices

1. Test behavior, not implementation
2. One assertion per test (ideally)
3. Clear test names
4. Fast test suite
5. Deterministic results
