Exp test maintainability

From managedcode/dotnet-skills · View interactive version

Exp test maintainability is an AI agent skill from the GitHub repository managedcode/dotnet-skills. 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 ref

How to use this skill

Skill file

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

When Not to Use

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:

Potential refactorings:

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:

Potential refactorings:

Category 3: Copy-paste test methods

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

Indicators:

Potential refactorings:

Category 4: Duplicated setup/teardown logic

Look for initialization or cleanup code repeated across test classes.

Indicators:

Potential refactorings:

Category 5: Repeated test infrastructure

Look for structural patterns shared across test classes.

Indicators:

Potential refactorings:

Step 3: Apply calibration rules

Before reporting, filter findings through these rules:

Step 4: Report findings

Present findings in this structure:

  1. Summary — How many patterns found, broken down by category. If the test suite is clean, lead with that.
  2. Findings by category — For each pattern found:
  1. Refactoring priority — Rank findings by:
  1. Trade-offs — For each suggestion, note:

Validation

Common Pitfalls

| Pitfall | Solution |

|---------|----------|

| Flagging AAA structure as duplication | The Arrange-Act-Assert pattern is not boilerplate — flag only when the actual code repeats |

| Suggesting extraction for 2 occurrences | Wait for 3+ before recommending extraction |

| Recommending base classes for everything | Prefer composition (helpers, factories) over inheritance |

| Ignoring the readability cost | Every extraction adds indirection — note the trade-off |

| Flagging simple new X() as boilerplate | Only flag complex construction with multiple parameters or configuration |

| Recommending DRY at the expense of test isolation | Tests that share mutable state through helpers become coupled — warn about this |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.