Best for
- User asks to audit, review, or analyze mock usage in .NET tests
- User wants to find unused, unnecessary, or redundant mock setups
- User wants to simplify test setup or reduce over-mocking
dotnet/skills/plugins/dotnet-experimental/skills/exp-mock-usage-analysis/SKILL.md
Audits .NET test mock usage by tracing each mock setup through the production code's execution path to find dead, unreachable, redundant, or replaceable mocks. Use when the user asks to audit mock usage, find unused or unnecessary mock setups, check if mocks are needed, reduce mock duplication or over-mocking, simplify test setup, or review whether mock configurations like ILogger/IOptions should use real implementations instead. Supports Moq, NSubstitute, and FakeItEasy.
Decision brief
Trace each mock setup through the production code's execution path to determine which setups are actually exercised at runtime and which are dead, unreachable, redundant, or replaceable with real implementations.
Compatibility matrix
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Not declared | No explicit evidence | Portability before use |
| Claude Code | Not declared | No explicit evidence | Portability before use |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/dotnet/skills --skill "plugins/dotnet-experimental/skills/exp-mock-usage-analysis"Inspect the Agent Skill "exp-mock-usage-analysis" from https://github.com/dotnet/skills/blob/1b896e91feb0f613cb54a914f1efd2897810ae02/plugins/dotnet-experimental/skills/exp-mock-usage-analysis/SKILL.md at commit 1b896e91feb0f613cb54a914f1efd2897810ae02. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
Read the test files and always read the production code. You cannot determine whether a mock setup is necessary without understanding the production method's control flow.
Read the test files and always read the production code. You cannot determine whether a mock setup is necessary without understanding the production method's control flow.
For each test method, do the following:
Flag mocks of stable framework types that should use real implementations: - Mock → NullLogger.Instance (unless log output is asserted) - Mock → Options.Create(new T { ... }) - Mocks of DTOs, records, or value objects → use new T { ... } directly
For each finding, state: 1. The specific test method and mock setup line 2. Why the setup is unnecessary (trace the production code path to explain) 3. A concrete fix — which lines to remove, what to replace them with, or how to extract shared setup
Permission review
No configured static risk pattern was detected
This is not proof of safety. Runtime behavior, indirect dependencies, and hidden external systems are outside the static scan.
Evidence record
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 91/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 5,248 | Source | Repository attention, not individual Skill quality |
| Compatibility | 0 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
Trace each mock setup through the production code's execution path to determine which setups are actually exercised at runtime and which are dead, unreachable, redundant, or replaceable with real implementations.
test-anti-patterns)| Input | Required | Description |
|---|---|---|
| Test code | Yes | Test files to analyze |
| Production code | Yes | Code under test — essential for tracing execution paths |
Read the test files and always read the production code. You cannot determine whether a mock setup is necessary without understanding the production method's control flow.
Identify the mock framework by scanning for its patterns:
new Mock<T>(), .Setup(...), .Verify(...)Substitute.For<T>(), .Returns(...), .Received(...)A.Fake<T>(), A.CallTo(...), .MustHaveHappened()Use the correct framework's terminology throughout your analysis.
For each test method, do the following:
.Setup, .Returns, A.CallTo, etc.)| Classification | Meaning | Example |
|---|---|---|
| Used | The production code calls this mock during the test's execution path | GetStock setup when Reserve is called and stock is sufficient |
| Unreachable | The production code returns early, throws, or branches away before reaching this mock call | UpdateStock setup when the test expects the method to throw ArgumentOutOfRangeException on the first line |
| Unused | The mock method is never called by the production method under test at all, regardless of inputs | GetLowStockProducts setup when testing Reserve, which never calls that method |
| Redundant | Identical mock configurations are duplicated across multiple tests instead of being shared | Five tests each creating new Mock<IPaymentGateway>() with the same default setup |
Pay special attention to:
.Verify/.Received/.MustHaveHappened without asserting on the method's return valueFlag mocks of stable framework types that should use real implementations:
Mock<ILogger<T>> → NullLogger<T>.Instance (unless log output is asserted)Mock<IOptions<T>> → Options.Create(new T { ... })new T { ... } directlyExplicitly confirm which mocks are correctly placed — external boundaries (databases, HTTP clients, message queues, third-party APIs) and security-sensitive types should remain mocked.
For each finding, state:
When multiple tests duplicate mock configurations, provide a before/after example showing how to extract shared setup into a fixture or helper method.
| Pitfall | Solution |
|---|---|
| Analyzing test code without reading production code | Always read the production method to trace which mocks are actually called |
| Flagging mocks for external boundaries (HTTP, DB) | These are valid isolation boundaries — keep them mocked |
Flagging ILogger mock when log output is asserted | Only flag when the mock is set up but log output is never verified |
| Using wrong framework terminology | Match the framework in the code: Moq (Setup/Verify), NSubstitute (Returns/Received), FakeItEasy (A.CallTo/MustHaveHappened) |
Frequently asked questions
Trace each mock setup through the production code's execution path to determine which setups are actually exercised at runtime and which are dead, unreachable, redundant, or replaceable with real implementations.
The source record exposes this install command: npx skills add https://github.com/dotnet/skills --skill "plugins/dotnet-experimental/skills/exp-mock-usage-analysis". Inspect the command and pinned source before running it.
Alternatives
alirezarezvani/claude-skills
App Store Optimization (ASO) toolkit for researching keywords, analyzing competitor rankings, generating metadata suggestions, and improving app visibility on Apple App Store and Google Play Store. Use when the user asks about ASO, app store rankings, app metadata, app titles and descriptions, app store listings, app visibility, or mobile app marketing on iOS or Android. Supports keyword research and scoring, competitor keyword analysis, metadata optimization, A/B test planning, launch checklist
trailofbits/skills
Constant-time testing detects timing side channels in cryptographic code. Use when auditing crypto implementations for timing vulnerabilities.
dotnet/skills
Analyzes test suites in any language and tags each test with standardized traits (positive, negative, critical-path, boundary, smoke, regression, integration, performance, security). Use when the user wants to categorize, audit, or label tests with traits. Works across .NET (MSTest/xUnit/NUnit/TUnit), Python (pytest), TS/JS (Jest/Vitest), Java, Go, Ruby, Rust, Swift, Kotlin, PowerShell, and C++ — auto-editing when the framework has canonical tag syntax, otherwise report-only. Do not use for writ
yonatangross/orchestkit
Grade work that already exists and decide whether it can merge. Runs the project's current unit, integration, and E2E suites plus security scanning and type checking, scores every dimension 0-10, and returns a merge verdict with a VERIFIED-vs-CLAIMED evidence manifest. Writes no test files and edits no source. Use when verifying changes are ready to merge. Use /ork:cover instead when the tests still have to be written.