polyglot-test-agent
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePolyglot Test Generation Skill
Polyglot 测试生成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:
- 为整个项目或特定文件生成单元测试
- 提升现有代码库的测试覆盖率
- 创建符合项目规范的测试文件
- 编写可实际编译并通过的测试
- 为新功能或未测试代码添加测试
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:
polyglot-test-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提交测试生成请求:
polyglot-test-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:
polyglot-test-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.mdpolyglot-test-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:
polyglot-test-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.mdpolyglot-test-planner- 将文件按逻辑分组为多个阶段(通常2-5个阶段)
- 按复杂度与依赖关系排序优先级
- 为每个文件指定测试用例
- 定义每个阶段的成功标准
输出文件:
.testagent/plan.mdStep 5: Implementation Phase (Automatic)
步骤5:实现阶段(自动执行)
The agent executes each phase sequentially:
polyglot-test-implementer- Read source files to understand the API
- Write test files following project patterns
- Build using the subagent to verify compilation
polyglot-test-builder - Test using the subagent to verify tests pass
polyglot-test-tester - Fix using the subagent if errors occur
polyglot-test-fixer - Lint using the subagent for code formatting
polyglot-test-linter
Each phase completes before the next begins, ensuring incremental progress.
polyglot-test-implementer- 读取源文件以理解API
- 编写符合项目模式的测试文件
- 构建:使用子Agent验证编译是否通过
polyglot-test-builder - 测试:使用子Agent验证测试是否通过
polyglot-test-tester - 修复:若出现错误,使用子Agent修复
polyglot-test-fixer - 格式化:使用子Agent格式化代码
polyglot-test-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 | Tools |
|---|---|---|
| Coordinates pipeline | runCommands, codebase, editFiles, search, runSubagent |
| Analyzes codebase | runCommands, codebase, editFiles, search, fetch, runSubagent |
| Creates test plan | codebase, editFiles, search, runSubagent |
| Writes test files | runCommands, codebase, editFiles, search, runSubagent |
| Compiles code | runCommands, codebase, search |
| Runs tests | runCommands, codebase, search |
| Fixes errors | runCommands, codebase, editFiles, search |
| Formats code | runCommands, codebase, search |
| Agent | 用途 | 工具 |
|---|---|---|
| 协调整个流程 | runCommands, codebase, editFiles, search, runSubagent |
| 分析代码库 | runCommands, codebase, editFiles, search, fetch, runSubagent |
| 创建测试计划 | codebase, editFiles, search, runSubagent |
| 编写测试文件 | runCommands, codebase, editFiles, search, runSubagent |
| 编译代码 | runCommands, codebase, search |
| 运行测试 | runCommands, codebase, search |
| 修复错误 | runCommands, codebase, editFiles, search |
| 格式化代码 | runCommands, codebase, search |
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.
polyglot-test-fixer.testagent/plan.mdpolyglot-test-fixer.testagent/plan.mdTests fail
测试失败
Review the test output and adjust test expectations. Some tests may require mocking dependencies.
查看测试输出并调整测试预期。部分测试可能需要模拟依赖项。
Wrong testing framework detected
检测到错误的测试框架
Specify your preferred framework in the initial request: "Generate Jest tests for..."
在初始请求中指定你偏好的框架:"Generate Jest tests for..."