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

exp-test-maintainability

하는 일

이 스킬은 .NET 테스트 코드에서 반복되는 설정, 검증, 복사 붙여넣기 테스트 메서드를 검토하고 정리 방법을 제안합니다. 테스트 프로젝트가 어수선하고 반복적으로 커진 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓테스트 파일에서 같은 설정이나 검증이 여러 번 반복될 때.
  • ✓비슷한 테스트 메서드 여러 개가 데이터 기반 테스트 하나로 합쳐질 수 있을 때.
  • ✓테스트를 아직 바꾸지 않고 테스트 스위트의 리팩터링 아이디어를 얻고 싶을 때.

스킬 링크

https://github.com/dotnet/skills/blob/main/plugins/dotnet-experimental/skills/exp-test-maintainability/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-test-maintainability/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에서 그대로 가져왔습니다.

Test Maintainability Assessment

Analyze .NET test code for maintainability issues: duplicated boilerplate, copy-paste test methods, and structural repetition across test methods and classes. Produce a report of refactoring opportunities with concrete before/after suggestions. The goal is analysis only — do not modify any files.

When to Use

  • User asks to find duplicated code or boilerplate in tests
  • User wants to know where test code can be DRY-ed up
  • User asks to reduce test duplication, improve test readability, or clean up test boilerplate
  • User asks for refactoring opportunities in a test suite
  • User wants to identify shared setup or teardown candidates
  • User asks "what patterns repeat across my tests?"
  • User wants to centralize test data, introduce builders or helpers

When Not to Use

  • User wants to write new tests from scratch (use writing-mstest-tests)
  • User wants to detect anti-patterns or code smells (use test-anti-patterns)
  • User wants to actually perform the refactoring (help them directly, this skill only analyzes)

Inputs

Input Required Description
Test code Yes One or more test files or a test project directory to analyze
Production code No The code under test, for context on what abstractions might help
Scope No Whether to analyze within a single class or across multiple classes

Workflow

Step 1: Gather the test code

Read all test files the user provides or references. If the user points to a directory or project, scan for all test files using these framework markers:

Framework Test class markers Test method markers
MSTest [TestClass] [TestMethod], [DataTestMethod]
xUnit (none — convention-based) [Fact], [Theory]
NUnit [TestFixture] [Test], [TestCase], [TestCaseSource]
TUnit (none — convention-based) [Test]

Step 2: Identify maintainability issues

Scan for these categories:

Category 1: Repeated object construction

Look for the same object being constructed in 3+ test methods with identical or near-identical parameters.

Indicators:

  • new ClassName(...) appearing with identical arguments in multiple tests
  • Multiple tests creating the same "system under test" with similar configuration
  • Repeated mock/fake/stub creation with the same setup

Potential refactorings:

  • Extract a factory method or test helper (e.g., CreateSut(), CreateDefaultOrder())
  • Use [TestInitialize]/constructor/[SetUp] for shared construction
  • Introduce a builder pattern for complex objects with many variations

Example — before:

[TestMethod]
public void Process_ValidOrder_Succeeds()
{
    var logger = new FakeLogger();
    var email = new FakeEmailService();
    var inventory = new FakeInventory(stock: 100);
    var processor = new OrderProcessor(logger, email, inventory);
    // ...
}

[TestMethod]
public void Process_EmptyItems_Fails()
{
    var logger = new FakeLogger();
    var email = new FakeEmailService();
    var inventory = new FakeInventory(stock: 100);
    var processor = new OrderProcessor(logger, email, inventory);
    // ...
}

After — extract factory:

private static OrderProcessor CreateProcessor(int stock = 100)
{
    return new OrderProcessor(new FakeLogger(), new FakeEmailService(), new FakeInventory(stock));
}

Category 2: Repeated assertion patterns

Look for the same sequence of assertions appearing in 3+ test methods.

Indicators:

  • Multiple tests asserting the same set of properties on a result object
  • Repeated null-check-then-value-check sequences
  • Same collection of Assert.AreEqual calls across methods

Potential refactorings:

  • Extract a custom assertion helper (e.g., AssertValidOrder(order, expectedTotal, expectedStatus))
  • Use framework-specific assertion extensions
  • Introduce a Verify method that checks a standard set of properties

Category 3: Copy-paste test methods

Look for test methods with near-identical bodies differing only in input values or a single parameter.

Indicators:

  • 3+ methods with the same structure but different literal values
  • Methods that could be collapsed into [DataRow]/[Theory]/[TestCase]
  • Test names that follow a pattern like Method_Input1_Result, Method_Input2_Result

Potential refactorings:

  • Convert to parameterized tests with [DataRow]/`
자주 묻는 질문

테스트 파일을 바꾸나요?

아니요. 분석만 하며, 적용할지 고를 수 있는 제안을 보고합니다.

매개변수화 테스트를 제안할 수 있나요?

네. 복사 붙여넣기 테스트를 데이터 기반 테스트로 바꾸자고 제안할 수 있습니다.

새 테스트를 쓰나요?

아니요. 새 테스트 작성은 다른 스킬이 담당합니다.

상세 정보

작성자의 원본 설명

Detects duplicate boilerplate, copy-paste tests, and structural maintainability issues across .NET test suites. Use when the user asks to reduce repetition, consolidate similar test methods, convert copy-paste tests to data-driven parameterized tests, suggest a better test structure, or identify refactoring opportunities. Identifies repeated construction, assertion patterns, copy-paste methods convertible to DataRow/Theory/TestCase, redundant setup/teardown, and shared infrastructure. Produces an analysis report with concrete before/after suggestions. Works with MSTest, xUnit, NUnit, and TUnit

repo: dotnet/skills

인기도

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

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬