crap-score
What it does
This skill calculates a CRAP score for a named .NET method, class or file. The score combines how complex code is with how well it is tested, so it highlights risky code. It is for developers deciding which code to test first.
When to use it
- ✓When you want the risk score for a specific method, class or file.
- ✓When you want to decide which tests to write first within one named piece of code.
- ✓When you want to judge whether a complicated method is safe to change.
Skill link
https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/crap-score/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“What is the CRAP score for the OrderProcessor class, and which of its methods should I test first?”
5 new skills a week. 1 minute to read.
How it works
The agent measures the complexity and coverage of the named code, applies the CRAP formula, and ranks the methods so the riskiest come first.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
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 Score | Risk Level | Interpretation |
|---|---|---|
| < 5 | Low | Simple and well-tested |
| 5 to < 15 | Moderate | Acceptable for most code |
| 15 to 30 | High | Needs more tests or simplification |
| > 30 | Critical | Refactor 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 what to test next within a named method, class, or file based on coverage-and-complexity risk
- User wants to evaluate test quality beyond simple coverage percentages
When Not to Use
- User just wants to run tests (use
run-testsskill) - User wants to write new tests (use
code-testing) - User only wants a coverage percentage without complexity analysis
- User wants project-wide coverage/CRAP analysis or priorities (use
coverage-analysis)
Inputs
| Input | Required | Description |
|---|---|---|
| Target scope | Yes | Method name, class name, or file path to analyze |
| Test project path | No | Path to the test project. Defaults to discovering test projects in the solution. |
| Source project path | No | Path to the source project under analysis |
Workflow
Step 1: Collect code coverage data
If the user supplies a valid Cobertura report that contains the requested
target, use it directly and do not rerun tests. If the supplied report is
malformed, empty, internally contradictory, or missing the target, treat it as
failed input: regenerate it with a repository-compatible command when possible,
or request a valid report when collection is unavailable. Otherwise invoke
run-tests to classify the repository's test platform and confirm the
compatible command shape, then require a command that emits Cobertura:
| Coverage provider | Cobertura command |
|---|---|
coverlet.collector with VSTest |
dotnet test <test.csproj> --collect:"XPlat Code Coverage" --results-directory <results-dir> |
Microsoft.Testing.Extensions.CodeCoverage with .NET 9 bridged MTP |
dotnet test <test.csproj> -- --coverage --coverage-output-format cobertura --coverage-output <output-path> |
Microsoft.Testing.Extensions.CodeCoverage with .NET 10+ native MTP |
dotnet test --project <test.csproj> --coverage --coverage-output-format cobertura --coverage-output <output-path> |
Use an equivalent repository-owned command when the project defines one. Search
the results directory recursively when the collector creates a GUID subfolder.
Do not substitute a generic binary .coverage command when no converter is
available.
Do not stop at the first restore, compilation, test, or collector failure. Classify the failing layer, inspect every report the command emitted, and exhaust non-persistent retries before asking for input. Safe retries include command-line MSBuild properties that leave source and manifests unchanged and an already-installed or repository-provided alternative collector. A trivial source error is a collection blocker, not the final analysis, when a reversible command-line setting can compile the same source. Never call an empty Cobertura file a successful fallback.
For classic non-SDK projects (ToolsVersion, explicit compile items, or
packages.config), use only a repository-provided coverage command that emits
Cobertura. If none exists, request Cobertura XML and stop; do not migrate the
project or inject an SDK-style provider. CRAP scores always require real
coverage data.
Never estimate coverage
Guessed coverage produces wrong CRAP scores, which is worse than no answer. For a classic project with no repository coverage command or existing report, stop here and request Cobertura.
Do not add coverage packages, change project manifests, or install global tools un
FAQ
What does a high CRAP score mean?
It means the code is complex and not well tested, so changes there are more likely to cause problems.
Can it score the whole project?
No. Project-wide coverage and CRAP analysis belong to a separate skill.
Does it write tests?
No. It shows priorities, while writing tests is handled by another skill.
Details
Original description by the author
Calculates CRAP (Change Risk Anti-Patterns) for a named .NET method, class, or file. USE FOR: explicit CRAP calculation or coverage-and-complexity risk within that named target, including which tests to prioritize. DO NOT USE FOR: project-wide coverage/CRAP, plateaus, or project-wide blockers/priorities (coverage-analysis); behavioral/pseudo-mutation gaps (test-gap-analysis); writing tests; test runs without CRAP context.
repo: dotnet/skills
Popularity
- GitHub stars
- 5.8k
- Ranking position
- #14626
- License
- MIT
- Updated
- 11/2/2026
Comments
- …
More skills from this repository
create-custom-agent
5.8kHelps your agent create VS Code custom agent files with their own tools, instructions and handoffs to other agents.
create-skill
5.8kHelps your agent create a new agent skill with a valid name, a clear trigger description and a SKILL.md file that follows the standard.
csharp-scripts
5.8kHelps your agent run a small C# program as a single file with the .NET command line tool, without creating a full project.
dotnet-pinvoke
5.8kHelps your agent call native C or C++ libraries from .NET correctly, covering signatures, string handling, memory and safe handles.
Similar skills
test-driven-development
311kTeaches your agent to write a failing test first, watch it fail, then write the smallest code that passes, before building any feature or fix.
verification-before-completion
311kTeaches your agent to run real checks and read their output before claiming that a task, fix, or build is complete or passing.
migrate-to-shoehorn
310kReplaces risky type casts in your test files with the shoehorn library, so tests can use partial data and still pass type checks.