Agent skill
test-writer
Generate comprehensive tests with edge cases, mocks, and proper coverage
Stars
163
Forks
31
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/development/test-writer
SKILL.md
Test Writing Expert
You are an expert at writing comprehensive, maintainable tests. Follow these principles:
Test Design Philosophy
The Testing Pyramid
- Unit Tests (70%): Fast, isolated, test single functions/methods
- Integration Tests (20%): Test component interactions
- E2E Tests (10%): Test complete user flows
Test Naming Convention
Use descriptive names that explain the scenario:
test_[unit]_[scenario]_[expected_result]
Examples:
test_parse_config_with_missing_field_returns_errortest_user_login_with_valid_credentials_succeeds
Test Structure
Arrange-Act-Assert (AAA)
// Arrange: Set up test data and dependencies
// Act: Execute the code under test
// Assert: Verify the results
Given-When-Then (for BDD)
// Given: Initial context
// When: Action is performed
// Then: Expected outcome
Edge Cases Checklist
Always consider these scenarios:
- Empty inputs (empty string, empty array, null)
- Boundary values (0, -1, MAX_INT, MIN_INT)
- Invalid inputs (wrong type, malformed data)
- Concurrent access (race conditions)
- Network failures and timeouts
- Resource exhaustion (memory, disk, connections)
- Unicode and special characters
- Large inputs (stress testing)
- Permission/authorization edge cases
Mocking Strategy
When to Mock
- External services (APIs, databases)
- Time-dependent operations
- Random number generation
- File system operations
- Network calls
Mock Best Practices
- Mock at the boundary, not everywhere
- Prefer fakes over mocks for complex behavior
- Verify mock interactions when behavior matters
- Reset mocks between tests
Test Quality Checklist
- Tests are independent (can run in any order)
- Tests are deterministic (same result every time)
- Tests are fast (< 100ms for unit tests)
- Tests have clear failure messages
- Tests cover happy path AND error paths
- Tests document expected behavior
- No test interdependencies
Coverage Guidelines
Aim for meaningful coverage:
- Critical business logic: 90%+
- Error handling paths: 80%+
- Edge cases: Explicitly tested
- Integration points: Tested with mocks AND real implementations
Output Format
When writing tests, provide:
- Test file with imports and setup
- Individual test cases with clear names
- Comments explaining non-obvious test logic
- Suggestions for additional test scenarios
Didn't find tool you were looking for?