polyglot-test-agent

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Polyglot 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
polyglot-test-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.
首先通过以下方式调用
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
测试生成器将自动管理整个流程。

Step 3: Research Phase (Automatic)

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

The
polyglot-test-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
polyglot-test-researcher
Agent会分析你的代码库,以了解:
  • 语言与框架:检测C#、TypeScript、Python、Go、Rust、Java等
  • 测试框架:识别MSTest、xUnit、Jest、pytest、go test等
  • 项目结构:映射源文件、现有测试及依赖项
  • 构建命令:探索项目的构建与测试方式
输出文件:
.testagent/research.md

Step 4: Planning Phase (Automatic)

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

The
polyglot-test-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
polyglot-test-planner
Agent会创建结构化的实现计划:
  • 将文件按逻辑分组为多个阶段(通常2-5个阶段)
  • 按复杂度与依赖关系排序优先级
  • 为每个文件指定测试用例
  • 定义每个阶段的成功标准
输出文件:
.testagent/plan.md

Step 5: Implementation Phase (Automatic)

步骤5:实现阶段(自动执行)

The
polyglot-test-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
    polyglot-test-builder
    subagent to verify compilation
  4. Test using the
    polyglot-test-tester
    subagent to verify tests pass
  5. Fix using the
    polyglot-test-fixer
    subagent if errors occur
  6. Lint using the
    polyglot-test-linter
    subagent for code formatting
Each phase completes before the next begins, ensuring incremental progress.
polyglot-test-implementer
Agent会按顺序执行每个阶段:
  1. 读取源文件以理解API
  2. 编写符合项目模式的测试文件
  3. 构建:使用
    polyglot-test-builder
    子Agent验证编译是否通过
  4. 测试:使用
    polyglot-test-tester
    子Agent验证测试是否通过
  5. 修复:若出现错误,使用
    polyglot-test-fixer
    子Agent修复
  6. 格式化:使用
    polyglot-test-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参考

AgentPurposeTools
polyglot-test-generator
Coordinates pipelinerunCommands, codebase, editFiles, search, runSubagent
polyglot-test-researcher
Analyzes codebaserunCommands, codebase, editFiles, search, fetch, runSubagent
polyglot-test-planner
Creates test plancodebase, editFiles, search, runSubagent
polyglot-test-implementer
Writes test filesrunCommands, codebase, editFiles, search, runSubagent
polyglot-test-builder
Compiles coderunCommands, codebase, search
polyglot-test-tester
Runs testsrunCommands, codebase, search
polyglot-test-fixer
Fixes errorsrunCommands, codebase, editFiles, search
polyglot-test-linter
Formats coderunCommands, codebase, search
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

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
polyglot-test-fixer
agent will attempt to resolve compilation errors. Check
.testagent/plan.md
for the expected test structure.
polyglot-test-fixer
Agent会尝试解决编译错误。可查看
.testagent/plan.md
了解预期的测试结构。

Tests 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..."