code-testing-agent

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Code Testing Generation Skill

代码测试生成Skill

An AI-powered skill that generates comprehensive, workable unit tests for any programming language using a coordinated multi-agent pipeline.
这是一个AI驱动的Skill,通过协同多Agent流水线为任意编程语言生成全面、可执行的单元测试。

When to Use This Skill

何时使用该Skill

Use this skill when you need to:
  • Generate unit tests for an entire project or specific files
  • Improve test coverage for existing codebases
  • Create test files that follow project conventions
  • Write tests that actually compile and pass
  • Add tests for new features or untested code
当你需要完成以下操作时可使用本Skill:
  • 为整个项目或特定文件生成单元测试
  • 提升现有代码库的测试覆盖率
  • 创建符合项目规范的测试文件
  • 编写可正常编译且测试通过的用例
  • 为新功能或未测试代码补充测试用例

When Not to Use

何时不使用

  • Running or executing existing tests (use the
    run-tests
    skill)
  • Migrating between test frameworks (use migration skills)
  • Writing tests specifically for MSTest patterns (use
    writing-mstest-tests
    )
  • Debugging failing test logic
  • 运行或执行现有测试(请使用
    run-tests
    skill)
  • 测试框架迁移(请使用迁移类skill)
  • 专门针对MSTest模式编写测试(请使用
    writing-mstest-tests
  • 调试失败的测试逻辑

How It Works

运行原理

This skill coordinates multiple specialized agents in a Research → Plan → Implement pipeline:
本Skill在调研 → 规划 → 落地的流水线中协调多个专业Agent:

Pipeline Overview

流水线概览

┌─────────────────────────────────────────────────────────────┐
│                     TEST GENERATOR                          │
│  Coordinates the full pipeline and manages state            │
└─────────────────────┬───────────────────────────────────────┘
        ┌─────────────┼─────────────┐
        ▼             ▼             ▼
┌───────────┐  ┌───────────┐  ┌───────────────┐
│ RESEARCHER│  │  PLANNER  │  │  IMPLEMENTER  │
│           │  │           │  │               │
│ Analyzes  │  │ Creates   │  │ Writes tests  │
│ codebase  │→ │ phased    │→ │ per phase     │
│           │  │ plan      │  │               │
└───────────┘  └───────────┘  └───────┬───────┘
                    ┌─────────┬───────┼───────────┐
                    ▼         ▼       ▼           ▼
              ┌─────────┐ ┌───────┐ ┌───────┐ ┌───────┐
              │ BUILDER │ │TESTER │ │ FIXER │ │LINTER │
              │         │ │       │ │       │ │       │
              │ Compiles│ │ Runs  │ │ Fixes │ │Formats│
              │ code    │ │ tests │ │ errors│ │ code  │
              └─────────┘ └───────┘ └───────┘ └───────┘
┌─────────────────────────────────────────────────────────────┐
│                     TEST GENERATOR                          │
│  Coordinates the full pipeline and manages state            │
└─────────────────────┬───────────────────────────────────────┘
        ┌─────────────┼─────────────┐
        ▼             ▼             ▼
┌───────────┐  ┌───────────┐  ┌───────────────┐
│ RESEARCHER│  │  PLANNER  │  │  IMPLEMENTER  │
│           │  │           │  │               │
│ Analyzes  │  │ Creates   │  │ Writes tests  │
│ codebase  │→ │ phased    │→ │ per phase     │
│           │  │ plan      │  │               │
└───────────┘  └───────────┘  └───────┬───────┘
                    ┌─────────┬───────┼───────────┐
                    ▼         ▼       ▼           ▼
              ┌─────────┐ ┌───────┐ ┌───────┐ ┌───────┐
              │ BUILDER │ │TESTER │ │ FIXER │ │LINTER │
              │         │ │       │ │       │ │       │
              │ Compiles│ │ Runs  │ │ Fixes │ │Formats│
              │ code    │ │ tests │ │ errors│ │ code  │
              └─────────┘ └───────┘ └───────┘ └───────┘

Step-by-Step Instructions

分步使用说明

Step 1: Determine the user request

步骤1:明确用户需求

Make sure you understand what user is asking and for what scope. When the user does not express strong requirements for test style, coverage goals, or conventions, source the guidelines from unit-test-generation.prompt.md. This prompt provides best practices for discovering conventions, parameterization strategies, coverage goals (aim for 80%), and language-specific patterns.
确保你理解用户的诉求和测试范围。如果用户没有对测试风格、覆盖率目标或规范提出明确要求,可以参考unit-test-generation.prompt.md中的规范。该提示文档提供了规范识别、参数化策略、覆盖率目标(建议达到80%)以及语言特定模式的最佳实践。

Step 2: Invoke the Test Generator

步骤2:调用测试生成器

Start by calling the
code-testing-generator
agent with your test generation request:
Generate unit tests for [path or description of what to test], following the [unit-test-generation.prompt.md](unit-test-generation.prompt.md) guidelines
The Test Generator will manage the entire pipeline automatically.
首先调用
code-testing-generator
Agent提交你的测试生成请求:
Generate unit tests for [path or description of what to test], following the [unit-test-generation.prompt.md](unit-test-generation.prompt.md) guidelines
测试生成器会自动管理整个流水线流程。

Step 3: Research Phase (Automatic)

步骤3:调研阶段(自动执行)

The
code-testing-researcher
agent analyzes your codebase to understand:
  • Language & Framework: Detects C#, TypeScript, Python, Go, Rust, Java, etc.
  • Testing Framework: Identifies MSTest, xUnit, Jest, pytest, go test, etc.
  • Project Structure: Maps source files, existing tests, and dependencies
  • Build Commands: Discovers how to build and test the project
Output:
.testagent/research.md
code-testing-researcher
Agent会分析你的代码库,明确以下信息:
  • 语言与框架:识别C#、TypeScript、Python、Go、Rust、Java等技术栈
  • 测试框架:识别MSTest、xUnit、Jest、pytest、go test等测试框架
  • 项目结构:梳理源文件、现有测试和依赖关系
  • 构建命令:获取项目的构建和测试执行方式
输出文件:
.testagent/research.md

Step 4: Planning Phase (Automatic)

步骤4:规划阶段(自动执行)

The
code-testing-planner
agent creates a structured implementation plan:
  • Groups files into logical phases (2-5 phases typical)
  • Prioritizes by complexity and dependencies
  • Specifies test cases for each file
  • Defines success criteria per phase
Output:
.testagent/plan.md
code-testing-planner
Agent会生成结构化的落地计划:
  • 将文件按逻辑分组到不同阶段(通常为2-5个阶段)
  • 按复杂度和依赖关系排序优先级
  • 为每个文件指定测试用例
  • 定义每个阶段的成功标准
输出文件:
.testagent/plan.md

Step 5: Implementation Phase (Automatic)

步骤5:落地阶段(自动执行)

The
code-testing-implementer
agent executes each phase sequentially:
  1. Read source files to understand the API
  2. Write test files following project patterns
  3. Build using the
    code-testing-builder
    sub-agent to verify compilation
  4. Test using the
    code-testing-tester
    sub-agent to verify tests pass
  5. Fix using the
    code-testing-fixer
    sub-agent if errors occur
  6. Lint using the
    code-testing-linter
    sub-agent for code formatting
Each phase completes before the next begins, ensuring incremental progress.
code-testing-implementer
Agent会按顺序执行每个阶段:
  1. 读取源文件理解API逻辑
  2. 编写符合项目规范的测试文件
  3. 调用
    code-testing-builder
    子Agent构建代码验证编译可用性
  4. 调用
    code-testing-tester
    子Agent执行测试验证用例可通过
  5. 出现错误时调用
    code-testing-fixer
    子Agent修复问题
  6. 调用
    code-testing-linter
    子Agent执行格式化规范代码风格
每个阶段完成后才会进入下一个阶段,保障进度可逐步验证。

Coverage Types

覆盖测试类型

  • Happy path: Valid inputs produce expected outputs
  • Edge cases: Empty values, boundaries, special characters
  • Error cases: Invalid inputs, null handling, exceptions
  • 正常路径:验证合法输入返回预期结果
  • 边界场景:空值、边界值、特殊字符等场景
  • 错误场景:非法输入、空值处理、异常抛出等场景

State Management

状态管理

All pipeline state is stored in
.testagent/
folder:
FilePurpose
.testagent/research.md
Codebase analysis results
.testagent/plan.md
Phased implementation plan
.testagent/status.md
Progress tracking (optional)
所有流水线状态都存储在
.testagent/
目录下:
文件用途
.testagent/research.md
代码库分析结果
.testagent/plan.md
分阶段落地计划
.testagent/status.md
进度跟踪(可选)

Examples

使用示例

Example 1: Full Project Testing

示例1:全项目测试

Generate unit tests for my Calculator project at C:\src\Calculator
Generate unit tests for my Calculator project at C:\src\Calculator

Example 2: Specific File Testing

示例2:指定文件测试

Generate unit tests for src/services/UserService.ts
Generate unit tests for src/services/UserService.ts

Example 3: Targeted Coverage

示例3:定向覆盖率提升

Add tests for the authentication module with focus on edge cases
Add tests for the authentication module with focus on edge cases

Agent Reference

Agent参考列表

AgentPurpose
code-testing-generator
Coordinates pipeline
code-testing-researcher
Analyzes codebase
code-testing-planner
Creates test plan
code-testing-implementer
Writes test files
code-testing-builder
Compiles code
code-testing-tester
Runs tests
code-testing-fixer
Fixes errors
code-testing-linter
Formats code
Agent用途
code-testing-generator
协调整条流水线
code-testing-researcher
分析代码库
code-testing-planner
生成测试计划
code-testing-implementer
编写测试文件
code-testing-builder
编译代码
code-testing-tester
执行测试
code-testing-fixer
修复错误
code-testing-linter
格式化代码

Requirements

使用要求

  • Project must have a build/test system configured
  • Testing framework should be installed (or installable)
  • VS Code with GitHub Copilot extension
  • 项目必须已配置构建/测试系统
  • 测试框架已安装(或支持自动安装)
  • 安装了GitHub Copilot扩展的VS Code

Troubleshooting

问题排查

Tests don't compile

测试无法编译

The
code-testing-fixer
agent will attempt to resolve compilation errors. Check
.testagent/plan.md
for the expected test structure. Check the
extensions/
folder for language-specific error code references (e.g.,
extensions/dotnet.md
for .NET).
code-testing-fixer
Agent会尝试解决编译错误。你可以查看
.testagent/plan.md
确认预期的测试结构,也可以查看
extensions/
目录下的语言特定错误码参考(例如.NET相关问题参考
extensions/dotnet.md
)。

Tests fail

测试执行失败

Most failures in generated tests are caused by wrong expected values in assertions, not production code bugs:
  1. Read the actual test output
  2. Read the production code to understand correct behavior
  3. Fix the assertion, not the production code
  4. Never mark tests
    [Ignore]
    or
    [Skip]
    just to make them pass
生成的测试出现失败大多是因为断言中的预期值错误,而非生产代码本身的Bug:
  1. 读取测试的实际输出结果
  2. 查看生产代码确认正确行为
  3. 修复断言内容,不要修改生产代码
  4. 不要为了通过测试就给用例标记
    [Ignore]
    [Skip]

Wrong testing framework detected

识别到错误的测试框架

Specify your preferred framework in the initial request: "Generate Jest tests for..."
在初始请求中指定你要使用的框架即可:"Generate Jest tests for..."

Environment-dependent tests fail

环境依赖型测试失败

Tests that depend on external services, network endpoints, specific ports, or precise timing will fail in CI environments. Focus on unit tests with mocked dependencies instead.
依赖外部服务、网络端点、特定端口或精准时序的测试在CI环境中会执行失败,建议优先编写基于Mock依赖的单元测试。

Build fails on full solution

全解决方案构建失败

During phase implementation, build only the specific test project for speed. After all phases, run a full non-incremental workspace build to catch cross-project errors.
阶段执行过程中,建议只构建对应的测试项目提升速度。所有阶段完成后,再执行全量非增量工作区构建来捕获跨项目错误。