본문으로 건너뛰기
Skillpedia
테스트5.8k · #14626

crap-score

하는 일

이 스킬은 지정한 .NET 메서드, 클래스, 파일의 CRAP 점수를 계산합니다. 이 점수는 코드의 복잡도와 테스트가 얼마나 잘 되었는지를 합쳐서 위험한 코드를 드러냅니다. 어느 코드를 먼저 테스트할지 정하는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓특정 메서드, 클래스, 파일의 위험 점수가 필요할 때.
  • ✓지정한 코드 한 부분 안에서 어떤 테스트를 먼저 쓸지 정하고 싶을 때.
  • ✓복잡한 메서드를 안전하게 바꿀 수 있는지 판단하고 싶을 때.

스킬 링크

https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/crap-score/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/crap-score/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“OrderProcessor 클래스의 CRAP 점수는 얼마인가요? 그중 어떤 메서드를 먼저 테스트해야 하나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트가 지정한 코드의 복잡도와 커버리지를 측정하고, CRAP 공식을 적용한 뒤, 가장 위험한 것이 먼저 오도록 메서드 순위를 매깁니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 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-tests skill)
  • 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

자주 묻는 질문

CRAP 점수가 높다는 것은 무엇을 뜻하나요?

코드가 복잡하고 테스트가 부족하다는 뜻이므로, 그 부분을 바꾸면 문제가 생기기 쉽습니다.

프로젝트 전체 점수를 낼 수 있나요?

아니요. 프로젝트 전체 커버리지와 CRAP 분석은 별도의 스킬이 다룹니다.

테스트를 쓰나요?

아니요. 우선순위를 보여 주며, 테스트 작성은 다른 스킬이 담당합니다.

상세 정보

작성자의 원본 설명

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

인기도

GitHub 스타
5.8k
순위
#14626
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬