关于 polyglot-test-agent
一个通过多 Agent 流程为项目或指定文件生成单元测试的技能,适用于需要补充测试或遵循现有项目约定的开发者。它将研究、规划、实现与构建、测试、修复和格式检查串联起来。
主要功能
- 01检测语言、测试框架和项目结构
- 02分阶段规划测试实现
- 03按项目模式编写单元测试
- 04构建并运行测试验证
- 05修复错误并检查格式
适用场景
- 01为整个项目生成单元测试
- 02为指定源文件补充测试
- 03为新功能或边界情况增加覆盖
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ github/ awesome-copilot --skill polyglot-test-agent安装后在 Claude Code 中输入/polyglot-test-agent确认已加载。
附带文件unit-test-generation.prompt.md
详细介绍
多语言测试生成技能
一个 AI 驱动的技能,使用协调的多 Agent 流水线为任何编程语言生成全面、可运行的单元测试。
何时使用此技能
当你需要执行以下操作时,请使用此技能:
- 为整个项目或特定文件生成单元测试
- 提高现有代码库的测试覆盖率
- 创建遵循项目约定的测试文件
- 编写真正能够编译并通过的测试
- 为新增功能或未经测试的代码添加测试
工作原理
此技能在 研究 → 规划 → 实现 流水线中协调多个专门的 Agent:
流水线概览
┌─────────────────────────────────────────────────────────────┐
│ 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 │
└─────────┘ └───────┘ └───────┘ └───────┘
分步说明
步骤 1:确定用户请求
确保你理解用户在询问什么以及范围是什么。 当用户未对测试风格、覆盖率目标或约定表达强烈需求时,请从 unit-test-generation.prompt.md 获取指导原则。该提示词提供了发现约定、参数化策略、覆盖率目标(目标为 80%)以及语言特定模式的最佳实践。
步骤 2:调用测试生成器
首先使用你的测试生成请求调用 polyglot-test-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
测试生成器将自动管理整个流水线。
步骤 3:研究阶段(自动)
polyglot-test-researcher Agent 分析你的代码库以了解:
- 语言与框架:检测 C#、TypeScript、Python、Go、Rust、Java 等。
- 测试框架:识别 MSTest、xUnit、Jest、pytest、go test 等。
- 项目结构:映射源文件、现有测试和依赖项
- 构建命令:发现如何构建和测试项目
输出:.testagent/research.md
步骤 4:规划阶段(自动)
polyglot-test-planner Agent 创建结构化的实现计划:
- 将文件分组为逻辑阶段(通常为 2-5 个阶段)
- 根据复杂度和依赖关系确定优先级
- 为每个文件指定测试用例
- 定义每个阶段的成功标准
输出:.testagent/plan.md
步骤 5:实现阶段(自动)
polyglot-test-implementer Agent 按顺序执行每个阶段:
- 读取源文件以了解 API
- 编写遵循项目模式的测试文件
- 使用
polyglot-test-builder子 Agent 构建以验证编译 - 使用
polyglot-test-tester子 Agent 测试以验证测试通过 - 如果出现错误,使用
polyglot-test-fixer子 Agent 修复 - 使用
polyglot-test-linter子 Agent 检查代码格式
每个阶段完成后才开始下一个阶段,确保增量进展。
覆盖类型
- 正常路径:有效输入产生预期输出
- 边界情况:空值、边界值、特殊字符
- 错误情况:无效输入、null 处理、异常
状态管理
所有流水线状态都存储在 .testagent/ 文件夹中:
| 文件 | 用途 |
|---|---|
.testagent/research.md | 代码库分析结果 |
.testagent/plan.md | 分阶段实现计划 |
.testagent/status.md | 进度跟踪(可选) |
示例
示例 1:完整项目测试
Generate unit tests for my Calculator project at C:\src\Calculator
示例 2:特定文件测试
Generate unit tests for src/services/UserService.ts
示例 3:针对性覆盖
Add tests for the authentication module with focus on edge cases
Agent 参考
| Agent | 用途 | 工具 |
|---|---|---|
polyglot-test-generator | 协调流水线 | runCommands, codebase, editFiles, search, runSubagent |
polyglot-test-researcher | 分析代码库 | runCommands, codebase, editFiles, search, fetch, runSubagent |
polyglot-test-planner | 创建测试计划 | codebase, editFiles, search, runSubagent |
polyglot-test-implementer | 编写测试文件 | runCommands, codebase, editFiles, search, runSubagent |
polyglot-test-builder | 编译代码 | runCommands, codebase, search |
polyglot-test-tester | 运行测试 | runCommands, codebase, search |
polyglot-test-fixer | 修复错误 | runCommands, codebase, editFiles, search |
polyglot-test-linter | 格式化代码 | runCommands, codebase, search |
要求
- 项目必须配置好构建/测试系统
- 应安装测试框架(或可安装)
- 带有 GitHub Copilot 扩展的 VS Code
故障排除
测试无法编译
polyglot-test-fixer Agent 将尝试解决编译错误。请查看 .testagent/plan.md 了解预期的测试结构。
测试失败
查看测试输出并调整测试预期。有些测试可能需要模拟依赖项。
检测到错误的测试框架
在初始请求中指定你偏好的框架:“Generate Jest tests for...”