{
  "schema": "https://ai-atoms.com/schemas/skill-v1.json",
  "type": "skill",
  "id": "skill/test-smell-detection",
  "version": "1.0.1",
  "name": "test-smell-detection",
  "description": "Audits existing tests in any language using formal, research-backed test smell names and the testsmells.org 19-smell academic taxonomy. Use when the caller asks for an academic or citable test-smell review, named smell categories, or a formal severity-ranked smell assessment. Covers Assertion Roulette, Conditional Test Logic, Mystery Guest, Eager Test, Sleepy Test, Unknown Test, Sensitive Equality, and the rest of the catalog across .NET, Python, JavaScript/TypeScript, Java, Go, Ruby, Rust, Swift, Kotlin, PowerShell, and C++. DO NOT USE FOR a quick pragmatic test review (use test-anti-patterns), writing or running tests, framework migration, coverage, or assertion-diversity metrics.",
  "system_prompt_fragment": "# Test Smell Detection\n\nDeep formal audit of test code using an academic test smell taxonomy. Detects symptoms of bad design or implementation decisions that make tests harder to understand, more fragile, less effective at catching bugs, or more expensive to maintain. Produces a severity-ranked report with specific locations and actionable fixes.\n\n## Why Test Smells Matter\n\nTest smells erode confidence in a test suite and inflate maintenance costs:\n\n| Problem | Consequence |\n|---------|-------------|\n| Tests with conditional logic | Some paths never execute — hidden testing gaps |\n| Tests that depend on external resources | Flaky failures, slow execution, environment coupling |\n| Tests that sleep to wait for results | Non-deterministic timing, slow suites, false failures |\n| Tests without assertions | False confidence — coverage looks good but nothing is verified |\n| Tests that call many production methods | Hard to diagnose failures, unclear what's being tested |\n| Tests with magic numbers | Unreadable intent, unclear boundary conditions |\n| Tests relying on ToString for comparison | Brittle to formatting changes, obscure failure messages |\n| Tests with exception handling logic | Swallowed failures, tests that pass when they shouldn't |\n\n## When to Use\n\n- User asks for a comprehensive or formal test smell audit\n- User asks \"are my tests well-written?\" and wants a thorough analysis\n- User wants a test quality health check with academic rigor\n- User asks for a review of test design or structure using standard smell categories\n- User suspects tests are fragile, flaky, or giving false confidence and wants a deep investigation\n\n## When Not to Use\n\n- User wants a quick pragmatic test review (use `test-anti-patterns` — faster, covers the most common issues)\n- User wants to evaluate assertion diversity specifically (use `assertion-quality`)\n- User wants to find duplicated boilerplate across tests (use `exp-test-maintainability`)\n- User wants to write new tests from scratch (help them directly)\n- User wants to fix a specific failing test (diagnose and fix directly)\n\n## Inputs\n\n| Input | Required | Description |\n|-------|----------|-------------|\n| Test code | Yes | One or more test files or a test project directory to analyze |\n| Production code | No | The code under test, for context on whether patterns are justified |\n\n## Workflow\n\n### Step 1: Gather the test code\n\nRead all test files the user provides. If the user points to a directory or project, scan for all test files by looking for test framework markers — see the `dotnet-test-frameworks` skill for .NET-specific markers.\n\nFor a thorough audit, also consult the [extended smell catalog](references/test-smell-catalog.md) which covers 9 additional smell types beyond the core 10 below.\n\n### Step 2: Scan for test smells\n\nFor each test method and class, check for the following smell categories:\n\n#### Smell 1: Conditional Test Logic\n\nTest methods containing `if`, `else`, `switch`, ternary (`? :`), `for`, `foreach`, or `while` statements. Control flow in tests means some paths may never execute, hiding gaps.\n\n**Severity:** High\n**Detection:** Any control flow statement inside a test method body.\n**Exception:** `foreach` used solely to assert every item in a known collection is acceptable when the assertion is the loop body.\n\n#### Smell 2: Mystery Guest\n\nTests that depend on external resources — files on disk, databases, network endpoints, environment variables — without making the dependency explicit or using test doubles.\n\n**Severity:** High\n**Detection:** Test methods that read files, open database connections, make HTTP requests (without a test handler), read environment variables, or use hard-coded file paths.\n**Exception:** In-memory fakes or test-specific handlers are fine.\n\n#### Smell 3: Sleepy Test\n\nTests that call sleep or delay functions to wait for a condition. These introduce non-deterministic timing and slow down the suite.\n\n**Severity:** High\n**Detection:** Calls to sleep/delay functions inside test methods. See the `dotnet-test-frameworks` skill for .NET-specific patterns.\n\n#### Smell 4: Assertion-Free Test (Unknown Test)\n\nTests that execute code but never assert anything. Test frameworks report these as passing even if the code is completely broken, as long as no exception is thrown.\n\n**Severity:** High\n**Detection:** A test method with no assertion calls (framework-specific: `Assert.*`, `expect()`, `assert`, `Should*`, etc.) and no expected-exception annotation.\n**Calibration:** A method named `*_DoesNotThrow` or `*_NoException` is implicitly asserting no exception — still flag it but note it may be intentional.\n\n#### Smell 5: Eager Test\n\nA test method that calls many different production methods, making it unclear what behavior is being tested. When it fails, diagnosis is difficult because the failure could stem from any of the calls.\n\n**Severity:** Medium\n**Detection:** A test method that calls 4+ distinct methods on the production object (excluding setup/construction). Count unique method names, not call count.\n**Calibration:** Integration tests or workflow tests may legitimately call multiple methods — note this as a possible exception for end-to-end scenarios.\n\n#### Smell 6: Magic Number Test\n\nAssertions that contain unexplained numeric literals. The intent of `Assert.AreEqual(42, result)` is unclear without context — what does 42 represent?\n\n**Severity:** Medium\n**Detection:** Numeric literals (other than 0, 1, -1, and the literal used in the test name) appearing as `expected` parameters in assertion methods.\n**Calibration:** Small integers in context (like count checks `Assert.AreEqual(3, list.Count)` where 3 items were just added) are acceptable — only flag when the number's meaning is genuinely unclear.\n\n#### Smell 7: Sensitive Equality\n\nTests that use `ToString()` for comparison or assertion. If the `ToString()` implementation changes, the test breaks even though the actual behavior is correct.\n\n**Severity:** Medium\n**Detection:** `Assert.AreEqual(expected, obj.ToString())`, or `.ToString()` appearing inside an assertion parameter.\n\n#### Smell 8: Exception Handling in Tests\n\nTests that contain `try`/`catch` blocks or `throw` statements. This typically means the test is manually managing exceptions rather than using the framework's built-in exception assertion facilities.\n\n**Severity:** Medium\n**Detection:** `try`/`catch` or `throw`/`raise` statements inside a test method.\n**Exception:** `catch` blocks that capture an exception for further assertion are a lesser concern — note but don't flag as high severity.\n\n#### Smell 9: General Fixture (Over-broad Setup)\n\nThe test setup method or constructor initializes fields that are not used by every test method. This means each test pays the cost of setting up objects it doesn't need.\n\n**Severity:** Low\n**Detection:** Fields initialized in setup that are referenced by fewer than half the test methods in the class.\n\n#### Smell 10: Ignored/Disabled Test\n\nTests marked as skipped or disabled. These add overhead and clutter, and the underlying issue they were disabled for may never be addressed.\n\n**Severity:** Low\n**Detection:** Skip/ignore annotations or conditional compilation that disables a test. See the `dotnet-test-frameworks` skill for framework-specific skip attributes.\n\n### Step 3: Apply calibration rules\n\nBefore reporting, calibrate findings to avoid false positives:\n\n- **Integration tests have different norms.** A test class clearly marked as integration (by name, annotation, or category) legitimately uses external resources, calls multiple methods, and may use delays for async coordination. Downgrade Mystery Guest, Eager Test, and Sleepy Test severity for integration tests — note them but don't flag as problems.\n- **Simple loop-assert patterns are fine.** Iterating a collection to assert on every item is readable and correct. Only flag loops with complex branching logic.\n- **Context matters for magic numbers.** A count assertion right after adding a known number of items is self-documenting. Only flag numbers whose meaning requires looking at production code to understand.\n- **Inconclusive/pending markers are not assertion-free.** Tests explicitly marked as incomplete should be flagged as Ignored Test, not Assertion-Free.\n- **Capture-and-assert exception patterns are borderline.** Try/catch patterns that capture an exception then assert on its properties are ugly but functional. Note as a smell and suggest the framework's built-in exception assertion instead of calling it broken.\n- **If the test suite is clean, say so.** A report finding few or no smells is perfectly valid.\n\n### Step 4: Report findings\n\nPresent the analysis in this structure:\n\n1. **Summary Dashboard** — Quick overview:\n   ```\n   | Severity | Smell Count | Affected Tests |\n   |----------|-------------|----------------|\n   | High     | 3           | 7              |\n   | Medium   | 2           | 4              |\n   | Low      | 1           | 2              |\n   | Total    | 6           | 13             |\n   ```\n\n2. **Findings by Severity** — For each smell found:\n   - Smell name and category\n   - Severity level with rationale\n   - Affected test methods (file and method name)\n   - Code snippet showing the smell\n   - Concrete fix: show what the code should look like after remediation\n   - Risk if left unfixed\n\n3. **Smell-Free Patterns** — If any test methods are well-written, briefly acknowledge this. Highlighting what's good helps the user understand the contrast.\n\n4. **Prioritized Remediation Plan** — Rank fixes by:\n   - Impact (high-severity smells affecting many tests first)\n   - Effort (quick fixes before refactoring)\n   - Risk (fixes that prevent false-passes before cosmetic improvements)\n\n## Validation\n\n- [ ] Every finding includes the specific test method name and file location\n- [ ] Every finding includes a code snippet showing the smell in context\n- [ ] Every finding includes a concrete fix example (not just \"fix this\")\n- [ ] Integration tests are not penalized for patterns that are appropriate for their scope\n- [ ] Simple foreach-assert loops are not flagged as conditional test logic\n- [ ] Contextually obvious numbers are not flagged as magic numbers\n- [ ] If the test suite is clean, the report says so upfront\n- [ ] Severity levels are justified, not arbitrary\n\n## Common Pitfalls\n\n| Pitfall | Solution |\n|---------|----------|\n| Flagging integration tests for using real resources | Check for integration test markers and adjust severity accordingly |\n| Flagging loop-over-collection-assert as conditional logic | Only flag loops with branching or complex logic, not assertion iterations |\n| Flagging obvious count assertions after adding N items | Consider the immediate context — self-documenting numbers are fine |\n| Missing framework-specific assertion syntax | Consult the `dotnet-test-frameworks` skill for .NET framework assertion and skip APIs |\n| Over-flagging try/catch that captures for assertion | Distinguish swallowed exceptions from capture-and-assert patterns |\n| Treating skip annotations with reasons same as bare skips | Note that reasoned skips are less concerning than unexplained ones |\n| Flagging `DoesNotThrow`-style tests as assertion-free | These implicitly assert no exception — note but acknowledge the intent |",
  "applicable_domains": [
    "code",
    "dotnet",
    "engineering"
  ],
  "invocation": [
    "/test-smell-detection"
  ],
  "tags": [
    "dotnet-test",
    "dotnet",
    "csharp",
    "microsoft"
  ],
  "authored_by": "anthropics",
  "source_url": "https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/test-smell-detection/SKILL.md",
  "lifecycle": "stable",
  "category": "dotnet",
  "provenance": {
    "source": "dotnet/skills",
    "source_url": "https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/test-smell-detection/SKILL.md",
    "author": "Microsoft / .NET Foundation",
    "license": "MIT",
    "notes": "Imported by scripts/import-anthropic-skills.py."
  }
}