Agent Skillsdotnet/skills › code-testing-agent

code-testing-agent

GitHub

自动生成跨语言单元测试,支持从单函数到全项目套件。采用多智能体流水线(研究-规划-实现),确保测试可编译并通过,适用于多种编程语言及遗留项目场景。

plugins/dotnet-test/skills/code-testing-agent/SKILL.md dotnet/skills

Trigger Scenarios

编写单元测试 生成测试代码 增加测试覆盖率 为未测试方法添加测试

Install

npx skills add dotnet/skills --skill code-testing-agent -g -y
More Options

Non-standard path

npx skills add https://github.com/dotnet/skills/tree/main/plugins/dotnet-test/skills/code-testing-agent -g -y

Use without installing

npx skills use dotnet/skills@code-testing-agent

指定 Agent (Claude Code)

npx skills add dotnet/skills --skill code-testing-agent -a claude-code -g -y

安装 repo 全部 skill

npx skills add dotnet/skills --all -g -y

预览 repo 内 skill

npx skills add dotnet/skills --list

SKILL.md

Frontmatter
{
    "name": "code-testing-agent",
    "license": "MIT",
    "description": "Generate or add unit tests for existing code, from one function to a complete project-wide suite. ALWAYS USE when asked to \"write unit tests\", \"add tests\", \"generate tests\", \"cover this untested method\", scaffold tests where none exist, or create comprehensive tests across multiple modules or packages. Polyglot: C#\/.NET, Python\/pytest, TS\/JS, Go, Rust, Java, Ruby. Handles classic non-SDK\/packages.config MSTest projects, explicit Compile registration, sparse workspaces, existing-suite extension, and proportional focused work. DO NOT USE for only running\/diagnosing tests, analyzing a coverage report, auditing test quality, or answering an MSTest API question without writing tests."
}

Code Testing Generation Skill

An AI-powered skill that generates comprehensive, workable unit tests for any programming language using a coordinated multi-agent pipeline.

Non-negotiable execution contract

Classify scope before editing:

  • Broad (a project/package-wide suite, or multiple production files/modules): create .testagent/research.md and .testagent/plan.md before implementation, then .testagent/status.md after the final test-quality review. If these files are absent, the broad workflow is incomplete.
  • Focused (the user explicitly limits work to one function/class/file or one missing method): do not create .testagent/ artifacts or fan out to multiple agents. A sparse project-wide request remains broad even when only one source module is present.

For either scope, run the narrowest relevant test command to a clean exit and finish with a compact Requirement | Evidence table. Each requested behavior must cite an exact test name; validation rows cite the successful command.

When to Use This 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
  • Generate or extend MSTest suites; load writing-mstest-tests as supporting guidance after this entry skill has established scope and project conventions

When Not to Use

  • Running or executing existing tests (use the run-tests skill)
  • Migrating between test frameworks (use migration skills)
  • Answering an MSTest API/pattern or modernization question that does not ask to generate tests (use writing-mstest-tests)
  • Debugging failing test logic

How It Works

This skill coordinates multiple specialized agents in a Research → Plan → Implement pipeline:

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  │
              └─────────┘ └───────┘ └───────┘ └───────┘

Step-by-Step Instructions

Step 1: Determine the user request

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.

Step 2: Size the request before invoking anything

Match the machinery to the scope. Running the full pipeline on a one-file request costs turns and tool calls without improving the tests.

Scope What it looks like How to run it
Focused One function, class, or file; "tests for X only"; extending an existing suite with the missing cases Skip the .testagent/ artifacts and the sub-agent fan-out. Keep the requirement checklist in your head (or in the final table), read only the target and one neighbouring test for conventions, write the tests, run the narrowest test command, review your own assertions inline.
Broad A project, package, or module set; "comprehensive suite"; a coverage threshold to clear across several files Run the full Research → Plan → Implement pipeline in Step 3, with the .testagent/ artifacts and the completion contract below.

When in doubt, start focused and escalate only if the request turns out to span several files. Escalating costs one extra pass; running the broad pipeline on a focused request costs several.

Step 3: Invoke the Test Generator (broad scope)

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. Treat the current workspace as authoritative even when it is sparse, gutted-looking, synthetic, or missing tracked files; never restore or reconstruct it, including with `git checkout`, `git restore`, `git reset`, or `git clean`.

The Test Generator will manage the entire pipeline automatically.

If code-testing-generator is unavailable, do not skip the workflow. Execute the same Research → Plan → Implement sequence inline, create the .testagent/ artifacts described below, and apply the same completion contract.

Step 4: Execute with bounded context

For multi-file requests:

  1. Turn every explicit user requirement into a checklist before implementation. Include requested layers, collaborators to mock, boundary cases, integrations, coverage thresholds, and report artifacts. Copy multi-condition requirements verbatim — they must each map to one test that exercises the whole combination.
  2. Research only the requested module or project and write the checklist plus a compact target inventory to .testagent/research.md.
  3. Reuse manifests, symbol references, and deterministic pairing tools instead of reading every source and test file.
  4. For multi-file scopes in C#, Python, TypeScript/JavaScript, Go, Java, Rust, or Ruby, run find-untested-sources once and consume its pairing and suggested-path output; do not repeat that discovery manually.
  5. Plan each target file once, then implement phases sequentially. Map every checklist item to at least one concrete test or explain why it is blocked.
  6. Build and test the narrow target during fix cycles; run workspace-level validation once at the end.
  7. Before reporting success, re-open the generated tests and verify every checklist item against concrete test names and assertions. Coverage alone is not evidence that a requested mock seam, boundary, state transition, or property combination was tested.
  8. Read a language example from code-testing-extensions only when the repository has no representative tests and the base extension is insufficient.
  9. For .NET, classify SDK-style vs. classic non-SDK before choosing commands or creating files. In classic projects, preserve packages.config, existing framework/mock versions and custom base fixtures, add every new test file to the project's explicit <Compile Include> items, and use the repository's MSBuild/test-runner commands. Never modernize the project or dependency stack merely to generate tests.

Completion contract

Every scope must satisfy points 3–5 below. Points 1 and 2 are the broad-scope artifacts: on a focused request the same reasoning happens inline and no .testagent/ files are written.

Do not report completion until all of these are true:

  1. (broad scope) .testagent/research.md records the bounded target inventory, existing test conventions, and the acceptance checklist.
  2. (broad scope) .testagent/plan.md maps each checklist item to a planned test or an explicit blocker.
  3. Generated tests compile and pass with the narrowest relevant test command.
  4. Every explicit user requirement is backed by a concrete test and assertion. Fix missing mock seams, boundary cases, state transitions, and property combinations even when coverage already passes. In the final summary, cite at least one generated test name for every checklist item so completion is auditable; if an item has no test to cite, keep implementing or report it as blocked. For non-behavioral requirements such as scaffolding, scope limits, commands, or coverage artifacts, cite the relevant file, command, or report instead of forcing a test-name mapping.
  5. Review the generated tests for behavior gaps and weak assertions. On a broad scope, invoke test-gap-analysis and assertion-quality when available and record the findings and fixes in .testagent/status.md. On a focused scope, do the equivalent review inline — re-read each generated assertion against the source — without spawning extra passes.

The final response MUST include a compact Requirement | Evidence table. Behavioral rows cite exact generated test names. Non-behavioral rows cite the relevant project file, validation command, or coverage report. A generic list of tested areas is not a substitute for requirement-by-requirement evidence.

Quote the user's requirement verbatim in each row. When the request names a specific combination — "a case where a composite discount, regional tax, and weight-based shipping all apply", "the difference between summed and chained discounts", "constructor validation for every class" — the row must cite the one test that demonstrates exactly that. A test that merely exercises the same collaborators does not satisfy a requirement about their interaction, and per-class requirements need a citation per class.

Cite a clean run, not an attempt. The commands behind the evidence table must have finished successfully: quote the final passing test summary and, when thresholds were requested, the per-module coverage table from a run that exited 0. If the last coverage run exited non-zero, fix it and re-run before reporting; never infer threshold clearance from a failed or partial run.

State Management

Broad-scope runs store pipeline state in the .testagent/ folder. A focused request does not create these files:

File Purpose
.testagent/research.md Codebase analysis results
.testagent/plan.md Phased implementation plan
.testagent/status.md Final quality review and fixes

Agent Reference

Agent Purpose
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

Requirements

  • Project must have a build/test system configured
  • Testing framework should be installed (or installable)
  • VS Code with GitHub Copilot extension

Classic non-SDK .NET projects are supported when their existing build/test toolchain is available. When it is not available on the current machine, the agent can still add and register version-compatible tests, but must report execution as blocked rather than substituting dotnet test.

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. Call the code-testing-extensions skill and read the language-specific extension file for error code references (e.g., dotnet.md for .NET).

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

Wrong testing framework detected

Specify your preferred framework in the initial request: "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.

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.

Version History

  • 7953ba8 Current 2026-08-14 01:13

    增强对经典 .NET 非 SDK 格式测试项目的支持,包括保留 packages.config 依赖、显式编译注册及兼容旧版 MSTest API。

  • ad0cfe8 2026-08-01 21:34

    修复Dotnet测试评估中的重复键YAML解析问题,解决场景数据覆盖错误;优化评估流程,消除部分P1成本并记录覆盖率缺口决策。

  • 5354047 2026-07-23 12:09

    升级智能体工作流并修复过时PR清理逻辑;优化 dotnet-test 评估覆盖率和效率;改进测试迁移技能指导;修复 fixture 命名空间导入问题。

  • ce75c35 2026-07-06 00:32

Same Skill Collection

.agents/skills/create-custom-agent/SKILL.md
.agents/skills/create-skill-test/SKILL.md
.agents/skills/create-skill/SKILL.md
.agents/skills/improve-skill-quality/SKILL.md
.github/skills/agentic-workflows/SKILL.md
eng/skill-validator/tests/fixtures/sample-skill/SKILL.md
plugins/dotnet-advanced/skills/csharp-scripts/SKILL.md
plugins/dotnet-advanced/skills/nuget-trusted-publishing/SKILL.md
plugins/dotnet-aspnetcore/skills/configuring-opentelemetry-dotnet/SKILL.md
plugins/dotnet-aspnetcore/skills/dotnet-webapi/SKILL.md
plugins/dotnet-aspnetcore/skills/minimal-api-file-upload/SKILL.md
plugins/dotnet-blazor/skills/create-blazor-project/SKILL.md
plugins/dotnet-blazor/skills/fetch-and-send-data/SKILL.md
plugins/dotnet-blazor/skills/support-prerendering/SKILL.md
plugins/dotnet-blazor/skills/use-js-interop/SKILL.md
plugins/dotnet-data/skills/optimizing-ef-core-queries/SKILL.md
plugins/dotnet-diag/skills/analyzing-dotnet-performance/SKILL.md
plugins/dotnet-diag/skills/clr-activation-debugging/SKILL.md
plugins/dotnet-diag/skills/dotnet-trace-collect/SKILL.md
plugins/dotnet-diag/skills/dump-collect/SKILL.md
plugins/dotnet-experimental/skills/exp-mock-usage-analysis/SKILL.md
plugins/dotnet-experimental/skills/exp-simd-vectorization/SKILL.md
plugins/dotnet-msbuild/skills/binlog-failure-analysis/SKILL.md
plugins/dotnet-msbuild/skills/copy-to-output-directory/SKILL.md
plugins/dotnet-msbuild/skills/msbuild-server/SKILL.md
plugins/dotnet-msbuild/skills/resolve-project-references/SKILL.md
plugins/dotnet-test-migration/skills/migrate-xunit-to-mstest/SKILL.md
plugins/dotnet-test-migration/skills/migrate-xunit-to-xunit-v3/SKILL.md
plugins/dotnet-test/skills/code-testing-extensions/SKILL.md
plugins/dotnet-test/skills/filter-syntax/SKILL.md
plugins/dotnet-test/skills/find-untested-sources/SKILL.md
plugins/dotnet-test/skills/platform-detection/SKILL.md
plugins/dotnet-test/skills/scaffold-dotnet-test-project/SKILL.md
plugins/dotnet-test/skills/test-gap-analysis/SKILL.md
plugins/dotnet-test/skills/testability-obstacle/SKILL.md
plugins/dotnet-upgrade/skills/dotnet-aot-compat/SKILL.md
.agents/skills/authoring-github-workflows/SKILL.md
plugins/dotnet-advanced/skills/dotnet-pinvoke/SKILL.md
plugins/dotnet-ai/skills/mcp-csharp-create/SKILL.md
plugins/dotnet-ai/skills/mcp-csharp-debug/SKILL.md
plugins/dotnet-ai/skills/mcp-csharp-test/SKILL.md
plugins/dotnet-ai/skills/technology-selection/SKILL.md
plugins/dotnet-aspnetcore/skills/convert-blazor-server-to-webapp/SKILL.md
plugins/dotnet-blazor/skills/author-component/SKILL.md
plugins/dotnet-blazor/skills/collect-user-input/SKILL.md
plugins/dotnet-blazor/skills/configure-auth/SKILL.md
plugins/dotnet-blazor/skills/coordinate-components/SKILL.md
plugins/dotnet-blazor/skills/plan-ui-change/SKILL.md
plugins/dotnet-data/skills/create-datadriven-aspnetcore/SKILL.md
plugins/dotnet-diag/skills/android-tombstone-symbolication/SKILL.md

Metadata

Files
0
Version
7953ba8
Hash
723a3e73
Indexed
2026-07-06 00:32

ホーム - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-15 02:24
浙ICP备14020137号-1 $お客様$