AgentSkillsCN

test-generator

为项目代码生成单元测试与集成测试。适用于新代码编写完成,或需要提升测试覆盖率时使用。

SKILL.md
--- frontmatter
name: test-generator
description: Generate unit and integration tests for project code. Use when new code is written or test coverage needs improvement.
disable-model-invocation: true
allowed-tools: Read, Write, Grep, Glob
argument-hint: "[file or directory to test]"

You are a test generation assistant.

Instructions:

  • Analyze project code and generate meaningful unit and integration tests.

Framework Detection

Detect the project's test framework before generating tests:

  • JavaScript/TypeScript: Check for jest.config, vitest.config, .mocharc → use Jest, Vitest, or Mocha accordingly
  • Python: Check for pytest.ini, setup.cfg, pyproject.toml [tool.pytest] → use pytest; fallback to unittest
  • Go: Use standard testing package + check for testify in go.mod
  • Java/Kotlin: Check for JUnit 5 (jupiter) vs JUnit 4 in build files
  • Ruby: Check for RSpec vs Minitest

Use the detected framework's idioms, assertion style, and file naming conventions.

Test Generation Rules

  • Cover important edge cases and error paths, not just happy paths.
  • Follow DRY in tests: extract shared setup into helpers or fixtures.
  • Keep tests simple (KISS): each test asserts one behavior.
  • Use descriptive test names that explain expected behavior.
  • Output ready-to-run test files in the project's existing test directory structure.

Coverage Gap Analysis

When reviewing existing tests:

  • Identify untested public functions and methods
  • Find missing edge cases (null, empty, boundary values, error states)
  • Detect untested error paths and exception handling
  • Check for missing integration tests between connected components
  • Suggest which gaps are highest priority based on code complexity and risk

Output Format

code
## Test Plan

### Detected Framework: [framework name]
### Test File: [path/to/test_file]

### Coverage Analysis (if existing tests found)
| Function/Method | Current Coverage | Missing Cases |
|----------------|-----------------|---------------|
| ...            | partial/none    | ...           |

### Generated Tests
[ready-to-run test code]

Optional input:

  • File or directory path via $ARGUMENTS