Exp Mock Usage Analysis
Audits .NET test mock usage by tracing each mock setup through the production code's...
Install
npx skills add dotnet/skills --skill exp-mock-usage-analysis -g -a claude-code -y- Repository
- dotnet/skills5.8k
- Category
- Testing
- Updated
- 3d ago
- License
- MIT
- Context cost
- Lightabout 1,326 tokens
- Runs scripts
- No, instructions only
What it does
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.
Mock Usage Analysis
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.
When to Use
- 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
- User asks whether mocks of ILogger, IOptions, or similar types are needed
When Not to Use
- User wants to write new mocks or tests (general testing guidance)
- User wants to detect non-mock test anti-patterns (use
test-anti-patterns) - User wants to migrate between mock frameworks (out of scope)
Inputs
| Input | Required | Description |
|---|---|---|
| Test code | Yes | Test files to analyze |
| Production code | Yes | Code under test, essential for tracing execution paths |
Workflow
Step 1: Read all provided code
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:
- Moq:
new Mock<T>(),.Setup(...),.Verify(...) - NSubstitute:
Substitute.For<T>(),.Returns(...),.Received(...) - FakeItEasy:
A.Fake<T>(),A.CallTo(...),.MustHaveHappened()
Use the correct framework's terminology throughout your analysis.
Step 2: Trace each mock setup through the production code
For each test method, do the following:
- Identify every mock setup line (
.Setup,.Returns,A.CallTo, etc.) - Read the production method being tested and trace its execution path for the specific inputs used in that test
- Determine which mock setups are actually reached during execution
- Classify each setup:


