code-testing-agent
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode 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 skill)
run-tests - Migrating between test frameworks (use migration skills)
- Writing tests specifically for MSTest patterns (use )
writing-mstest-tests - Debugging failing test logic
- 运行或执行现有测试(请使用skill)
run-tests - 测试框架迁移(请使用迁移类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 agent with your test generation request:
code-testing-generatorGenerate unit tests for [path or description of what to test], following the [unit-test-generation.prompt.md](unit-test-generation.prompt.md) guidelinesThe Test Generator will manage the entire pipeline automatically.
首先调用 Agent提交你的测试生成请求:
code-testing-generatorGenerate 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 agent analyzes your codebase to understand:
code-testing-researcher- 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.mdcode-testing-researcher- 语言与框架:识别C#、TypeScript、Python、Go、Rust、Java等技术栈
- 测试框架:识别MSTest、xUnit、Jest、pytest、go test等测试框架
- 项目结构:梳理源文件、现有测试和依赖关系
- 构建命令:获取项目的构建和测试执行方式
输出文件:
.testagent/research.mdStep 4: Planning Phase (Automatic)
步骤4:规划阶段(自动执行)
The agent creates a structured implementation plan:
code-testing-planner- 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.mdcode-testing-planner- 将文件按逻辑分组到不同阶段(通常为2-5个阶段)
- 按复杂度和依赖关系排序优先级
- 为每个文件指定测试用例
- 定义每个阶段的成功标准
输出文件:
.testagent/plan.mdStep 5: Implementation Phase (Automatic)
步骤5:落地阶段(自动执行)
The agent executes each phase sequentially:
code-testing-implementer- Read source files to understand the API
- Write test files following project patterns
- Build using the sub-agent to verify compilation
code-testing-builder - Test using the sub-agent to verify tests pass
code-testing-tester - Fix using the sub-agent if errors occur
code-testing-fixer - Lint using the sub-agent for code formatting
code-testing-linter
Each phase completes before the next begins, ensuring incremental progress.
code-testing-implementer- 读取源文件理解API逻辑
- 编写符合项目规范的测试文件
- 调用子Agent构建代码验证编译可用性
code-testing-builder - 调用子Agent执行测试验证用例可通过
code-testing-tester - 出现错误时调用子Agent修复问题
code-testing-fixer - 调用子Agent执行格式化规范代码风格
code-testing-linter
每个阶段完成后才会进入下一个阶段,保障进度可逐步验证。
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 folder:
.testagent/| File | Purpose |
|---|---|
| Codebase analysis results |
| Phased implementation plan |
| Progress tracking (optional) |
所有流水线状态都存储在目录下:
.testagent/| 文件 | 用途 |
|---|---|
| 代码库分析结果 |
| 分阶段落地计划 |
| 进度跟踪(可选) |
Examples
使用示例
Example 1: Full Project Testing
示例1:全项目测试
Generate unit tests for my Calculator project at C:\src\CalculatorGenerate unit tests for my Calculator project at C:\src\CalculatorExample 2: Specific File Testing
示例2:指定文件测试
Generate unit tests for src/services/UserService.tsGenerate unit tests for src/services/UserService.tsExample 3: Targeted Coverage
示例3:定向覆盖率提升
Add tests for the authentication module with focus on edge casesAdd tests for the authentication module with focus on edge casesAgent Reference
Agent参考列表
| Agent | Purpose |
|---|---|
| Coordinates pipeline |
| Analyzes codebase |
| Creates test plan |
| Writes test files |
| Compiles code |
| Runs tests |
| Fixes errors |
| Formats code |
| Agent | 用途 |
|---|---|
| 协调整条流水线 |
| 分析代码库 |
| 生成测试计划 |
| 编写测试文件 |
| 编译代码 |
| 执行测试 |
| 修复错误 |
| 格式化代码 |
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 agent will attempt to resolve compilation errors. Check for the expected test structure. Check the folder for language-specific error code references (e.g., for .NET).
code-testing-fixer.testagent/plan.mdextensions/extensions/dotnet.mdcode-testing-fixer.testagent/plan.mdextensions/extensions/dotnet.mdTests fail
测试执行失败
Most failures in generated tests are caused by wrong expected values in assertions, not production code bugs:
- Read the actual test output
- Read the production code to understand correct behavior
- Fix the assertion, not the production code
- Never mark tests or
[Ignore]just to make them pass[Skip]
生成的测试出现失败大多是因为断言中的预期值错误,而非生产代码本身的Bug:
- 读取测试的实际输出结果
- 查看生产代码确认正确行为
- 修复断言内容,不要修改生产代码
- 不要为了通过测试就给用例标记或
[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.
阶段执行过程中,建议只构建对应的测试项目提升速度。所有阶段完成后,再执行全量非增量工作区构建来捕获跨项目错误。