Official agent skill

Crap Score

by microsoft in microsoft/testfx

Calculates targeted CRAP (Change Risk Anti-Patterns) scores for a named .NET method, class, or single source file.

OfficialMITAuto-check passedTesting & QA

Install Crap Score

skills CLI
$ npx skills add microsoft/testfx --skill crap-score -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install microsoft/testfx crap-score --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/microsoft/testfx.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/crap-score .claude/skills/crap-score && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
crap-score
GitHub stars
1k
Token cost
~1.9k tokens
SKILL.md length
843 words
Files
1
Skills in repo
44
Repo updated
First seen
Licence
MIT

At a glance

Calculates targeted CRAP (Change Risk Anti-Patterns) scores for a named .NET method, class, or single source file.

  • Works in 6 steps: Collect code coverage data → Compute cyclomatic complexity → Extract per-method coverage from… → …
  • The user explicitly asks to compute CRAP scores
  • SKILL.md covers Background, When to Use, When Not to Use and Inputs, plus 3 more sections
  • Calls dotnet

What it does

Crap Score is an agent skill from microsoft/testfx, published by the product's own GitHub organization. Calculates targeted CRAP (Change Risk Anti-Patterns) scores for a named .NET method, class, or single source file. Use when the user explicitly asks to compute CRAP scores or assess risky untested code for a specific target, combining Cobertura coverage data with cyclomatic complexity analysis. DO NOT USE FOR: project-wide coverage analysis, coverage plateau or "stuck coverage" diagnosis, what's blocking coverage, or where to add tests across a project (use coverage-analysis); writing tests; running tests without…

Its SKILL.md is about 1.9k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Testing & QA, covering Test coverage. It works with .NET. The repository describes itself as: This repository holds the source code of Microsoft.Testing.Platform (MTP), a lightweight alternative to VSTest, as well as MSTest adapter and framework. The licence is MIT.

When your agent uses it

  • The user explicitly asks to compute CRAP scores
  • Assess risky untested code for a specific target
  • Combining Cobertura coverage data with cyclomatic complexity analysis
  • : project-wide coverage analysis

Example prompts

  • “stuck coverage”
  • “Use the crap-score skill to calculate targeted CRAP (Change Risk Anti-Patterns) scores for a named .NET method, class, or single source file”
  • “/crap-score”

Workflow steps

6 steps, taken from the step headings in SKILL.md.

  1. Collect code coverage data
  2. Compute cyclomatic complexity
  3. Extract per-method coverage from Cobertura XML
  4. Calculate CRAP scores
  5. Present results
  6. Provide actionable recommendations

What it can do on your machine

Read from SKILL.md and the folder at commit 7c7d590. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • dotnet

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Crap Score loads about 1.9k tokens when it runs. Until then it costs about 136 tokens; SKILL.md has 843 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~136
When it runs · the whole SKILL.md, loaded when a task matches
~1.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from microsoft/testfx at commit 7c7d590, republished under its MIT licence (© microsoft). 843 words, ~1,927 tokens.

Download SKILL.mdSave it as .claude/skills/crap-score/SKILL.md (or your agent's skills folder).
name
crap-score
description
Calculates targeted CRAP (Change Risk Anti-Patterns) scores for a named .NET method, class, or single source file. Use when the user explicitly asks to compute CRAP scores or assess risky untested code for a specific target, combining Cobertura coverage data with cyclomatic complexity analysis. DO NOT USE FOR: project-wide coverage analysis, coverage plateau or "stuck coverage" diagnosis, what's blocking coverage, or where to add tests across a project (use coverage-analysis); writing tests; running tests without CRAP context.
license
MIT

CRAP Score Analysis

Calculate CRAP (Change Risk Anti-Patterns) scores for .NET methods to identify code that is both complex and undertested.

Background

The CRAP score combines cyclomatic complexity and code coverage into a single metric:

$$\text{CRAP}(m) = \text{comp}(m)^2 \times (1 - \text{cov}(m))^3 + \text{comp}(m)$$

Where:

  • $\text{comp}(m)$ = cyclomatic complexity of method $m$
  • $\text{cov}(m)$ = code coverage ratio (0.0 to 1.0) of method $m$
CRAP ScoreRisk LevelInterpretation
< 5LowSimple and well-tested
5-15ModerateAcceptable for most code
15-30HighNeeds more tests or simplification
> 30CriticalRefactor and add coverage urgently

A method with 100% coverage has CRAP = complexity (the minimum). A method with 0% coverage has CRAP = complexity^2 + complexity.

When to Use

  • User wants to assess which methods are risky due to low coverage and high complexity
  • User asks for CRAP score of specific methods, classes, or files
  • User wants to prioritize which code to test next
  • User wants to evaluate test quality beyond simple coverage percentages

When Not to Use

  • User just wants to run tests (use run-tests skill)
  • User wants to write new tests (use writing-mstest-tests skill or general coding assistance)
  • User only wants a coverage percentage without complexity analysis

Inputs

InputRequiredDescription
Target scopeYesMethod name, class name, or file path to analyze
Test project pathNoPath to the test project. Defaults to discovering test projects in the solution.
Source project pathNoPath to the source project under analysis

Workflow

Step 1: Collect code coverage data

If no coverage data exists yet (no Cobertura XML available), always run dotnet test with coverage collection first and mention the exact command in your response. Do not skip this step -- CRAP scores require coverage data.

Check the test project's .csproj for the coverage package, then run the appropriate command:

Coverage PackageCommandOutput Location
coverlet.collectordotnet test --collect:"XPlat Code Coverage" --results-directory ./TestResultsTypically under TestResults/<guid>/coverage.cobertura.xml. Search recursively under the results directory (for example, TestResults/**/coverage.cobertura.xml) or use any explicit coverage path the user provides.
Microsoft.Testing.Extensions.CodeCoverage (.NET 9)dotnet test -- --coverage --coverage-output-format cobertura --coverage-output ./TestResults--coverage-output path
Microsoft.Testing.Extensions.CodeCoverage (.NET 10+)dotnet test --coverage --coverage-output-format cobertura --coverage-output ./TestResults--coverage-output path
Step 2: Compute cyclomatic complexity

Analyze the target source files to determine cyclomatic complexity per method. Count the following decision points (each adds 1 to the base complexity of 1):

ConstructExample
ifif (x > 0)
else ifelse if (y < 0)
case (each)case 1:
forfor (int i = 0; ...)
foreachforeach (var item in list)
whilewhile (running)
do...whiledo { } while (cond)
catch (each)catch (Exception ex)
&&if (a && b)
|| (OR)if (a || b)
??value ?? fallback
?.obj?.Method()
? : (ternary)x > 0 ? a : b
Pattern match armx is > 0 and < 10

Base complexity is 1 for every method. Each decision point adds 1.

When analyzing, read the source file and count these constructs per method. Report the breakdown.

Step 3: Extract per-method coverage from Cobertura XML

Parse the Cobertura XML to find each method's line-rate attribute under the target <class> element. If line-rate is not available at method level, compute it from the <lines> elements:

$$\text{cov}(m) = \frac{\text{lines with hits} > 0}{\text{total lines}}$$

Method names in Cobertura may differ from source (async methods, lambdas). Match by line ranges when names don't align.

Show full SKILL.md (313 more words)Show less
Step 4: Calculate CRAP scores

For each method in scope, apply the formula:

$$\text{CRAP}(m) = \text{comp}(m)^2 \times (1 - \text{cov}(m))^3 + \text{comp}(m)$$

Step 5: Present results

Present a sorted table (highest CRAP first):

text
| Method                          | Complexity | Coverage | CRAP Score | Risk     |
|---------------------------------|------------|----------|------------|----------|
| OrderService.ProcessOrder       | 12         | 45%      | 28.4       | High     |
| OrderService.ValidateItems      | 8          | 90%      | 8.1        | Moderate |
| OrderService.CalculateTotal     | 3          | 100%     | 3.0        | Low      |

Include:

  • Summary: total methods analyzed, how many in each risk category
  • Top offenders: methods with CRAP > 30, with specific recommendations
  • Quick wins: methods with high complexity but where small coverage improvements would drop the score significantly
Step 6: Provide actionable recommendations

For high-CRAP methods, suggest one or both:

  1. Add tests -- identify uncovered branches and suggest specific test cases
  2. Reduce complexity -- suggest extract-method refactoring for deeply nested logic

Calculate the coverage needed to bring a method below a CRAP threshold of 15:

$$\text{cov}_{\text{needed}} = 1 - \left(\frac{15 - \text{comp}}{\text{comp}^2}\right)^{1/3}$$

This formula only applies when comp < 15. When comp >= 15, the minimum possible CRAP score (at 100% coverage) is comp itself, which already meets or exceeds the threshold. In that case, coverage alone cannot bring the CRAP score below the threshold -- the method must be refactored to reduce its cyclomatic complexity first.

Report this as: "To bring ProcessOrder (complexity 12) below CRAP 15, increase coverage from 45% to at least 72%." For methods where complexity alone exceeds the threshold, report: "ComplexMethod (complexity 18) cannot reach CRAP < 15 through testing alone -- reduce complexity by extracting sub-methods."

Validation

  • Verify that coverage data was collected successfully (Cobertura XML exists and contains data)
  • Cross-check that method names in coverage data match the source code
  • Confirm CRAP scores by spot-checking the formula on one method manually
  • Ensure a 100%-covered method's CRAP equals its complexity exactly

Common Pitfalls

  • Stale coverage data: Always regenerate coverage before computing CRAP scores. Old coverage files will produce misleading results.
  • Method name mismatches: Cobertura XML may use mangled/compiler-generated names for async methods, lambdas, or local functions. Match by line ranges when names don't align.
  • Generated code: Exclude auto-generated files (e.g., *.Designer.cs, *.g.cs) from analysis unless explicitly requested.

© microsoft, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/crap-score of microsoft/testfx.

Open the folder on GitHubat commit 7c7d590

Compare with similar skills

Crap Score next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Crap Score compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Crap Score this skillmicrosoft/testfx1k—~1.9kAutomated safety check: PassMIT
Evaluate PR Testsdotnet/maui23k—~2.9kAutomated safety check: PassMIT
Find Untested Sourcesdotnet/skills5.6k1 repos~3.3kAutomated safety check: PassMIT
Coverage Analysisrunceel/ReactiveProperty944—~5.9kAutomated safety check: WarnMIT
Stryker Dotnetardalis/RiverBooks135—~1.9kAutomated safety check: PassNone
Coverage Analysis for .NETdotnet/skills5.6k1 repos~2.8kAutomated safety check: PassMIT

Similar skills

  • Official

    Reviews the tests added in a pull request for fix coverage, quality, edge cases and test type, and recommends lighter test types where they would do.

    23k GitHub stars~2.9k tokensUpdated today
    Testing & QAAuto-check passed
  • Official

    Statically pairs source files with test files to list code that no test references, using Roslyn for C# or tree-sitter for many languages, with no build.

    5.6k GitHub starsUsed in 1 repo~3.3k tokens
    Testing & QAAuto-check passed
  • Coverage Analysis

    runceel/ReactiveProperty

    Automated, project-wide code coverage and CRAP (Change Risk Anti-Patterns) score analysis for .NET projects with existing unit tests.

    944 GitHub stars~5.9k tokensUpdated 1 mo ago
    Testing & QAAuto-check: warnings
  • Stryker Dotnet

    ardalis/RiverBooks

    Run Stryker.NET mutation testing against a specific .NET source file.

    135 GitHub stars~1.9k tokensUpdated today
    Testing & QAAuto-check passed
  • Official

    Interprets .NET coverage reports to explain line and branch gaps, target arithmetic and, on request, CRAP-based risk hotspots, without rerunning tests.

    5.6k GitHub starsUsed in 1 repo~2.8k tokens
    Testing & QAAuto-check passed
  • Coverage

    Log2n-io/Typhon

    Run code coverage analysis, track class-level results, and generate trend reports

    250 GitHub stars~787 tokensUpdated yesterday
    Testing & QAAuto-check passed

More from microsoft/testfx

All 44 skills in this repo
  • Official

    Guide for organizing MSBuild infrastructure with Directory.Build.props, Directory.Build.targets, Directory.Packages.props, and Directory.Build.rsp.

    1k GitHub starsUsed in 1 repo~2.5k tokens
    Auto-check passed
  • Binlog Failure Analysis

    microsoft/testfx

    Official

    Analyze MSBuild binary logs to diagnose build failures. An agent skill from microsoft/testfx.

    1k GitHub starsUsed in 3 repos~730 tokens
    Auto-check passed
  • Coverage Analysis

    microsoft/testfx

    Official

    Project-wide code coverage and CRAP (Change Risk Anti-Patterns) score analysis for .NET projects.

    1k GitHub stars~7.3k tokensUpdated today
    Auto-check passed
  • Incremental Build

    microsoft/testfx

    Official

    Guide for optimizing MSBuild incremental builds. An agent skill from microsoft/testfx.

    1k GitHub starsUsed in 3 repos~3.7k tokens
    Auto-check passed
  • Msbuild Modernization

    microsoft/testfx

    Official

    Guide for modernizing and migrating MSBuild project files to SDK-style format.

    1k GitHub starsUsed in 3 repos~4.3k tokens
    Auto-check passed
  • Msbuild Antipatterns

    microsoft/testfx

    Official

    Catalog of MSBuild anti-patterns with detection rules and fix recipes.

    1k GitHub stars~4.5k tokensUpdated today
    Auto-check passed

Works with

Categories

Questions about Crap Score

What does Crap Score do?

Calculates targeted CRAP (Change Risk Anti-Patterns) scores for a named .NET method, class, or single source file. Crap Score is an agent skill from microsoft/testfx, published by the product's own GitHub organization.NET method, class, or single source file.

When should I use Crap Score?

Crap Score fits situations like: the user explicitly asks to compute CRAP scores; assess risky untested code for a specific target; combining Cobertura coverage data with cyclomatic complexity analysis; : project-wide coverage analysis.

How do I install Crap Score in Claude Code?

Run `npx skills add microsoft/testfx --skill crap-score -a claude-code`. Or copy the skill folder (.agents/skills/crap-score in microsoft/testfx) into .claude/skills/crap-score in your project. Claude Code loads it when a task matches its description.

How do I install Crap Score in Codex?

Run `npx skills add microsoft/testfx --skill crap-score -a codex`. Or copy the skill folder (.agents/skills/crap-score in microsoft/testfx) into .agents/skills/crap-score in your project. Codex loads it when a task matches its description.

Can I use Crap Score in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add microsoft/testfx --skill crap-score -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/crap-score, .gemini/skills/crap-score, .github/skills/crap-score and .opencode/skills/crap-score in your project.

What does Crap Score need to run?

Going by SKILL.md and its folder, Crap Score needs the command-line tools its instructions call (dotnet).

Does Crap Score access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Crap Score safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Crap Score use?

Crap Score is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Crap Score use?

About 1.9k tokens (SKILL.md is roughly 7.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Crap Score?

Skills that share tags, products or a category with Crap Score: Evaluate PR Tests (dotnet/maui, 23k stars), Find Untested Sources (dotnet/skills, 5.6k stars), Coverage Analysis (runceel/ReactiveProperty, 944 stars) and Stryker Dotnet (ardalis/RiverBooks, 135 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Crap Score?

microsoft (a GitHub organization, an official publisher) maintains it in microsoft/testfx, which has 1,047 GitHub stars. The repository holds 44 skills in this directory. The repository was last updated on October 8, 2026.

Source: microsoft/testfx on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.