| name | testing |
| description | Use when writing tests, designing test strategy, or verifying AI-generated code |
Testing
Announce at start: "Following the testing skill for test design."
Core Rule
Test behavior, not implementation. Tests must survive refactoring.
Test Pyramid
Write tests in this ratio:
| Layer | Quantity | Speed | Focus |
|---|
| Unit | Many (1000s) | Fast (ms) | Individual functions/classes |
| Integration | Some (100s) | Medium (s) | Component interactions |
| E2E | Few (10s) | Slow (min) | Full user flows |
Writing Tests
1. Structure: Arrange-Act-Assert
Every test follows AAA:
def test_order_total_includes_tax():
order = Order(items=[Item(price=100)])
tax = TaxCalculator(rate=0.08)
total = order.calculate_total(tax)
assert total == 108.00
2. Naming: Describe Behavior
| Pattern | Example |
|---|
test_<unit>_<scenario> | test_login_with_invalid_password |
test_<unit>_<scenario>_<expected> | test_discount_exceeds_max_caps_at_max |
3. Data: Explicit, Not Magic
- Use explicit test data in each test
- Avoid shared fixtures with hidden setup
- Use builder patterns for complex objects
Coverage Priorities
| Priority | What to Test |
|---|
| High | Business logic, data mutations, security/auth, payments |
| Medium | Utility functions, error handling, integration points |
| Low | Generated code, configuration, UI styling |
Critical paths (payments, auth, data mutations) always require 100% coverage.
AI-Specific Rules
Bug Fix Tests
Every bug fix must include a regression test that:
- Fails before the fix (proves the bug)
- Passes after the fix (proves the fix)
- Prevents recurrence
Related Skills
Deep Reference
For principles, rationale, anti-patterns, and examples:
guides/testing-strategy/testing-strategy.md
guides/testing-ai-code/testing-ai-code.md