// Write focused tests for core user flows and critical paths with clear test names, behavior-focused assertions, mocked external dependencies, and fast execution, deferring edge case testing until explicitly required. Use this skill when creating or modifying test files, writing unit tests, integration tests, or test cases for any feature. Apply when writing test files (test/, __tests__/, spec/, .test.js, .spec.ts, test_*.py), implementing tests for core user workflows, testing critical business logic, mocking external dependencies (databases, APIs, file systems), writing descriptive test names, creating fast-running unit tests, or adding tests at logical completion points of feature development. Use for any task involving test creation, test coverage, test strategy, or test-driven development.
| name | Testing Writing Guidelines |
| description | Write focused tests for core user flows and critical paths with clear test names, behavior-focused assertions, mocked external dependencies, and fast execution, deferring edge case testing until explicitly required. Use this skill when creating or modifying test files, writing unit tests, integration tests, or test cases for any feature. Apply when writing test files (test/, __tests__/, spec/, .test.js, .spec.ts, test_*.py), implementing tests for core user workflows, testing critical business logic, mocking external dependencies (databases, APIs, file systems), writing descriptive test names, creating fast-running unit tests, or adding tests at logical completion points of feature development. Use for any task involving test creation, test coverage, test strategy, or test-driven development. |
Core Philosophy: Write minimal, focused tests for critical paths. Defer comprehensive testing until explicitly requested.
This Skill provides Claude Code with specific guidance on how to adhere to coding standards as they relate to how it should handle testing test writing.
Do NOT write tests for:
DO write tests for:
Pattern:
1. Implement feature completely
2. Identify critical paths
3. Write tests for those paths only
4. Move to next feature
Priority 1 - Always Test:
Priority 2 - Test When Requested:
Priority 3 - Defer:
Use descriptive names following pattern: test_<function>_<scenario>_<expected_result>
Good:
test_checkout_with_valid_cart_creates_order()
test_login_with_correct_credentials_returns_token()
Bad:
test_checkout()
test_user_login()
Test what the code does, not how it does it.
Good - Tests behavior:
def test_discount_calculation_applies_percentage():
result = calculate_discount(price=100, rate=0.2)
assert result == 80
Bad - Tests implementation:
def test_discount_uses_multiplication():
# Don't test internal calculation method
assert discount._multiply_called == True
Isolate units by mocking external systems.
Always mock:
Example:
@mock.patch('app.database.query')
def test_fetch_user_returns_user_data(mock_query):
mock_query.return_value = {'id': 1, 'name': 'Test'}
result = fetch_user(1)
assert result['name'] == 'Test'
Unit tests must execute in milliseconds.
Fast tests enable:
If test is slow:
Before writing a test, ask:
When following TDD:
Over-testing during development:
Under-testing critical paths:
Brittle tests:
| Scenario | Action |
|---|---|
| Implementing new feature | Test critical path only |
| User requests edge case testing | Add those specific tests |
| Non-critical utility function | Skip testing unless requested |
| Core business calculation | Always test |
| Error handling | Defer unless business-critical |
| Integration point | Test at completion |