मुख्य सामग्री पर जाएँ
Skillpedia
टेस्टिंग5.8k · #14581

exp-test-maintainability

यह क्या करती है

यह स्किल .NET test code में दोहराया गया setup, assertions और copy-paste test methods देखती है, फिर बताती है कि उन्हें कैसे व्यवस्थित करें। यह उन डेवलपर के लिए है जिनके test projects उलझे और दोहराव वाले हो गए हैं।

कब इस्तेमाल करें

  • ✓जब आपकी test फ़ाइलें वही setup या assertions कई बार दोहराती हों।
  • ✓जब कई मिलते-जुलते test methods एक data-driven test बन सकें।
  • ✓जब आप test suite के लिए refactoring के विचार चाहें, बिना अभी उसे बदले।

Skill का लिंक

https://github.com/dotnet/skills/blob/main/plugins/dotnet-experimental/skills/exp-test-maintainability/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/dotnet/skills/blob/main/plugins/dotnet-experimental/skills/exp-test-maintainability/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“मेरे payments test project में दोहराया गया setup और copy-paste tests खोजिए और उसके लिए एक साफ़ ढाँचा सुझाइए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

एजेंट test फ़ाइलें और जहाँ उपयोगी हो वहाँ test किया जा रहा code पढ़ता है, फिर पहले और बाद के सुझावों के साथ दोहराए गए पैटर्न की रिपोर्ट देता है। यह फ़ाइलें नहीं बदलता।

तकनीकी सामग्री (मूल 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]/`
अक्सर पूछे जाने वाले सवाल

क्या यह मेरी test फ़ाइलें बदलती है?

नहीं। यह सिर्फ़ विश्लेषण के लिए है, और सुझाव देती है जिन्हें आप लागू करना चुन सकते हैं।

क्या यह parameterized tests सुझा सकती है?

हाँ। यह copy-paste tests को data-driven tests में बदलने का सुझाव दे सकती है।

क्या यह नए tests लिखती है?

नहीं। नए tests लिखने के लिए अलग स्किल इस्तेमाल होती है।

जानकारी

लेखक का मूल विवरण

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
अपडेट की गई
2/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills