generate-tests
Generate comprehensive, maintainable test suites through code analysis. Use when the user asks to write tests, create unit tests, add test cases, test a function, or improve test coverage.
When & Why to Use This Skill
This Claude skill automates the creation of comprehensive and maintainable test suites by performing deep code analysis. It helps developers ensure software reliability by generating high-quality unit tests, identifying edge cases, and improving overall code coverage across multiple programming languages and frameworks such as Jest, Pytest, and JUnit.
Use Cases
- Automatically generating unit tests for newly developed functions or modules to ensure immediate code quality and functional correctness.
- Enhancing existing test suites by identifying and adding missing edge cases, boundary conditions, and error-handling scenarios that might be overlooked.
- Improving legacy code reliability by analyzing existing logic and generating missing tests to increase overall code coverage without manual effort.
- Standardizing testing practices across a team by following consistent naming conventions and professional mocking principles for external dependencies and APIs.
| name | generate-tests |
|---|---|
| description | 'Generate comprehensive, maintainable test suites through code analysis. Use when the user asks to write tests, create unit tests, add test cases, test a function, or improve test coverage.' |
| compatibility | Requires test framework and code read/write tools |
| - Bash(node | *, npm:*, npx:*, pnpm:*, yarn:*, python:*, pip:*, pytest:*, go:*, cargo:*, mvn:*, ./mvnw:*, gradle:*, ./gradlew:*, make:*, cmake:*, g++:*, gcc:*, clang:*) |
Test Generation Skill
Generate comprehensive, maintainable tests through code analysis.
Test Generation Process
- Analyze code: signature/I-O, branches, deps/side effects.
Tools:
mcp__serena__find_symbol(signatures),mcp__context7__get-library-docs(framework docs). - Check existing patterns:
find . -name "*.test.*" -o -name "*_test.*" -o -name "test_*"grep -r "describe\\|it\\|test\\|expect" --include="*.test.*" | head -5
- Design cases:
- AAA: Arrange → Act → Assert.
- Coverage: happy path, edge(boundary/empty/null), error(invalid/exception), integration interactions.
Framework Templates
Load only the framework you need:
- Jest(JS/TS):
references/jest.md - Vitest(JS/TS):
references/vitest.md - pytest(Python):
references/pytest.md - Go:
references/go.md - JUnit(Java):
references/java-junit.md - Kotlin test:
references/kotlin-test.md
Test Naming Conventions
Descriptive test names
should_return_expected_result_when_valid_inputreturns_empty_array_for_empty_inputthrows_error_for_negative_input
Mocking Guidelines
What to Mock
- External API calls
- Database operations
- File system access
- Time-related functions
- Random functions
Mocking Principles
- Use minimal mocking
- Configure to behave like real implementation
- Mock at interface boundaries
- Test behavior, not implementation details
Output Format
## Test Generation Result
### Target
- File: `path/to/file`
- Function: `functionName`
### Generated Tests
- Total N test cases
- Happy Path: N
- Edge Cases: N
- Error Cases: N
### Test File
`path/to/test/file`
### How to Run
```bash
npm test -- --testPathPattern="filename"
pytest path/to/test_file.py -v
go test ./... -run TestFunctionName
```
Coverage Improvement Suggestions
- [Additional test case suggestions]
Edge Cases
- No test file exists: Create new test file
- Existing tests: Maintain consistent style, add only new cases
- Untestable code: Suggest refactoring
- Complex mocking required: Offer integration test alternative
Notes
- MCP tools are optional; omit if unavailable or add others as needed