AgentSkillsCN

gen-test

为指定模块或函数生成单元测试。

SKILL.md
--- frontmatter
name: gen-test
description: Generate unit tests for a specified module or function
invocation: user
user_invocation: /gen-test

Generate Tests

Generate comprehensive unit tests for the specified module or function. Follow the project's existing test patterns and conventions.

Context

  • Test framework: Vitest
  • Test file naming: *.test.ts colocated with source
  • Packages: @yubot/shared, @yubot/backend, @yubot/agent-runtime, @yubot/mobile
  • Run tests: bun run test (all) or bun --filter <package> test (single package)

Steps

  1. Read the target module/function specified by the user
  2. Identify the public API, edge cases, and error conditions
  3. Read 1-2 existing test files to match the project's testing style:
    • packages/backend/src/server.test.ts — Fastify server.inject() pattern
    • packages/shared/src/index.test.ts — simple assertion pattern
  4. Generate tests covering:
    • Happy path for each public function/method
    • Edge cases (empty input, null, boundary values)
    • Error conditions (invalid input, thrown exceptions)
    • For agent tools: mock execute params, verify output shape and side effects
  5. Write the test file next to the source file (e.g., foo.tsfoo.test.ts)
  6. Run bun --filter <package> test to verify the new tests pass

Output Format

Write the test file and report:

  • Number of test cases generated
  • Coverage areas (happy path, edge cases, errors)
  • Any tests that need manual review