dotnet-testing-code-coverage-analysis

A guide to code coverage, a measurement of which parts of a program run while tests execute. It explains coverage reports, Coverlet, Visual Studio, and VS Code, and notes that a high percentage alone does not prove the tests are good.

In plain words
What is it for?
Use it to collect .NET coverage reports, inspect line or branch coverage, use Visual Studio or VS Code views, and add coverage checks to CI/CD, automated build and test pipelines.
Why use it?
It helps find code that tests never exercise and supports decisions about where more testing is needed without treating the percentage as a guarantee of correctness.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/kevintsengtw/dotnet-testing-agent-skills/dotnet-testing-code-coverage-analysis
Any agent
npx skills add kevintsengtw/dotnet-testing-agent-skills --skill dotnet-testing-code-coverage-analysis
Clone the repo
git clone --depth 1 https://github.com/kevintsengtw/dotnet-testing-agent-skills

Made for: Claude Code, Codex.

Per session 216 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,935 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00216 $0.02935
Opus 5 $0.00108 $0.01468
Sonnet 5 $0.00043 $0.00587
Haiku 4.5 $0.00022 $0.00294

Measured 3d ago against content hash 20ecf6d67b7e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

dotnet-testing-code-coverage-analysis scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/dotnet-testing-code-coverage-analysis/SKILL.md · 214 lines

How it starts

The opening of the file, as written. The whole thing — 214 lines — stays where its author put it; the contents beside it link to each section on GitHub.

程式碼覆蓋率分析指南

Code Coverage 核心概念

程式碼覆蓋率 (Code Coverage) 是一種測量指標,用來統計測試執行時實際執行了多少程式碼。

實際價值: 找出測試盲點、評估測試完整性、輔助重構決策、增加測試信心。

常見誤解:

  • 涵蓋率 100% 不代表沒有 Bug — 只代表程式碼有被執行,不代表驗證了正確行為
  • 涵蓋率數字越高不一定越好 — 重點是測試的有效性
  • 把涵蓋率當作 KPI 會適得其反 — 開發者會為了衝數字而寫沒有 Assert 的測試

覆蓋率工具選擇

工具 優點 適用場景
Visual Studio Enterprise 內建整合,完整 UI 僅 Enterprise
Fine Code Coverage(推薦) 免費,即時顯示,編輯器直接標示 VS 所有版本
.NET CLI + Coverlet 跨平台,CLI 自動化 CI/CD 流程
VS Code 內建 跨平台,無需額外擴充套件 VS Code 開發

Fine Code Coverage 設定

  • 安裝方式: Visual Studio 延伸模組管理 → 搜尋 "Fine Code Coverage" → 安裝
  • 必要設定: 工具 → 選項 → Fine Code Coverage → Enable: True、Editor Colouring Line Highlighting: True

VS Code 內建測試覆蓋率

  1. 安裝 C# Dev Kit 擴充套件
  2. 開啟測試總管(燒杯圖示)
  3. 點選「執行涵蓋範圍測試」
  4. 查看結果:測試涵蓋範圍視圖、編輯器內顯示、檔案總管顯示

執行覆蓋率分析

# .NET CLI(推薦用於 CI/CD)
dotnet test --collect:"XPlat Code Coverage"
dotnet test --collect:"XPlat Code Coverage" --results-directory ./coverage

# Fine Code Coverage:在 VS 中執行測試後自動顯示
# VS Code:開啟測試總管 → 點選「執行涵蓋範圍測試」

方法說明

方法 工具 操作步驟
.NET CLI Coverlet + CLI 執行 dotnet test --collect:"XPlat Code Coverage"
Fine Code Coverage VS 擴充套件 在 VS 中執行測試後自動顯示
VS Code C# Dev Kit 開啟測試總管 → 執行涵蓋範圍測試

設定 Coverlet

測試專案需安裝 coverlet.collector 套件,並可透過 runsettings 檔案進行進階設定(排除規則、閾值、報告格式)。

完整 csproj 配置範例請參考 references/coverlet-csproj-config.md

解讀覆蓋率報告

顏色標示: 綠色(已覆蓋)、黃色(部分覆蓋)、紅色(未覆蓋)

覆蓋率指標:

  1. Line Coverage(行覆蓋率) — 被執行的行數 / 總行數,最基本的指標
  2. Branch Coverage(分支覆蓋率) — 被執行的分支數 / 總分支數,比行覆蓋率更準確
  3. Method Coverage(方法覆蓋率) — 被執行的方法數 / 總方法數

Read the full file on GitHub · 214 lines

Files

What ships with it

5 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 214 lines · 216 tokens per session scan A 20ecf6d67b7e

Subscribe to this mod's changes

dotnet-testing-code-coverage-analysis is a skill published in the GitHub repository kevintsengtw/dotnet-testing-agent-skills (28 stars, last pushed 18d ago), licensed MIT. It adds 216 tokens to every session and 2,935 once invoked, about $0.0011 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

clean-architecture-dotnet

Use when domain logic leaks into API/Infrastructure, project references violate layer boundaries, or you need to decide between CQS (always), CQRS bus (complex domains), and DDD patterns (invariants and events).

SebastienDegodez/copilot-instructions · 50 tokens

mutation-testing

Use when running mutation testing, killing mutants, verifying test quality, checking mutation score, or analyzing survivors after the test baseline is green.

SebastienDegodez/copilot-instructions · 29 tokens

generate-microcks-openapi-samples

Use when creating OpenAPI mock examples for Microcks, setting up request/response routing with dispatchers, or mapping request fields to mock responses.

SebastienDegodez/copilot-instructions · 37 tokens

outside-in-tdd

Use when writing tests from the outside-in, defining behavior before code, or any feature where tests should start from observable business behavior and let internal design emerge.

SebastienDegodez/copilot-instructions · 35 tokens

extracting-code-structure

Use when listing all methods, functions, or classes in a file, exploring unfamiliar code, getting API overviews, or deciding what to read selectively without loading entire files.

SebastienDegodez/copilot-instructions · 39 tokens

querying-yaml

Use when querying YAML files, filtering or transforming configuration data, or extracting specific fields from large YAML files like docker-compose.yml or GitHub Actions workflows without loading entire files (saves 80-95% context).

SebastienDegodez/copilot-instructions · 48 tokens