본문으로 건너뛰기
Skillpedia
테스트5.8k · #14580

exp-mock-usage-analysis

하는 일

이 스킬은 .NET 테스트를 검사해 테스트 대상 코드가 실제로 사용하는 목 설정이 무엇인지 보여 줍니다. 목 설정이 무겁거나 복잡한 테스트 스위트를 가진 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓.NET 테스트에서 사용되지 않거나 불필요한 목 설정을 찾고 싶을 때.
  • ✓테스트 설정이 무겁게 느껴져서 단순하게 만들고 싶을 때.
  • ✓로깅이나 옵션 타입의 목이 정말 필요한지 궁금할 때.

스킬 링크

https://github.com/dotnet/skills/blob/main/plugins/dotnet-experimental/skills/exp-mock-usage-analysis/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/dotnet/skills/blob/main/plugins/dotnet-experimental/skills/exp-mock-usage-analysis/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“제 주문 서비스 테스트의 목을 감사해서, 코드가 전혀 사용하지 않는 설정이 무엇인지 알려 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트가 테스트와 운영 코드를 읽고, 각 목 설정을 코드의 실행 경로를 따라 추적한 뒤, 어떤 설정이 사용되지 않거나 중복되거나 교체할 수 있는지 보고합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

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:

  1. Identify every mock setup line (.Setup, .Returns, A.CallTo, etc.)
  2. Read the production method being tested and trace its execution path for the specific inputs used in that test
  3. Determine which mock setups are actually reached during execution
  4. Classify each setup:
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:

  • Early returns and guard clauses — setups for mocks called after a guard clause are unreachable when the guard triggers
  • Exception throws — if the method throws before using dependencies, all setups for those dependencies are unnecessary
  • Branch-specific logic — if a method dispatches by channel/type, setups for other channels are unused
  • Verify-only tests — tests that only call .Verify/.Received/.MustHaveHappened without asserting on the method's return value

Step 3: Check for replaceable mocks

Flag 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 { ... })
  • Mocks of DTOs, records, or value objects → use new T { ... } directly

Explicitly confirm which mocks are correctly placed — external boundaries (databases, HTTP clients, message queues, third-party APIs) and security-sensitive types should remain mocked.

Step 4: Report findings

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

When multiple tests duplicate mock configurations, provide a before/after example showing how to extract shared setup into a fixture or helper method.

Validation

  • Production code was read and execution paths were traced (not just test code reviewed)
  • Every finding references a specific test method and setup line
  • Unreachable setups include an explanation of which production code path makes them unreach
자주 묻는 질문

새 테스트를 쓰나요?

아니요. 기존 목을 감사하고 더 단순한 설정을 제안합니다.

운영 코드가 필요한가요?

네. 어떤 목에 도달하는지 알려면 테스트 대상 코드를 읽어야 합니다.

어떤 목 프레임워크를 아나요?

Moq, NSubstitute, FakeItEasy 같은 흔한 .NET 목 라이브러리를 인식합니다.

상세 정보

작성자의 원본 설명

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.

repo: dotnet/skills

인기도

GitHub 스타
5.8k
순위
#14580
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬