Skip to content

Conversation

@ChristianMurphy
Copy link
Member

@ChristianMurphy ChristianMurphy commented Nov 23, 2025

Checklist
Description of change

Add CRAP Score Analysis Task for Test Coverage Prioritization

This PR adds a Gradle task that generates prioritized reports identifying which code poses the highest risk when modified. CRAP (Change Risk Anti-Patterns) combines cyclomatic complexity and test coverage to quantify modification risk using the formula CRAP = complexity² × (1 - coverage)³ + complexity. Methods with CRAP > 30 are high-risk and should either have comprehensive tests added or be refactored to reduce complexity before modification. Methods with complexity > 30 cannot achieve CRAP < 30 even with 100% test coverage and must be refactored. Traditional coverage metrics treat all uncovered code equally, but a simple getter with 0% coverage carries far less risk than complex business logic with 0% coverage.

The task parses existing JaCoCo XML reports and generates an interactive HTML report showing methods ranked by CRAP score, package-level statistics for broad coverage planning, and color-coded risk indicators. It exports CSV for custom analysis and prints a console summary showing the top 10 highest-CRAP methods and packages with the most untested complexity. Before modifying legacy code, run the analysis to check CRAP scores. CRAP < 10 indicates relatively safe code to modify. CRAP 10-30 requires adding tests before major changes. CRAP > 30 requires either comprehensive tests to bring the score below 30, or refactoring if complexity exceeds 30. The HTML report includes a usage guide and the Packages Overview tab identifies entire packages with high uncovered complexity for systematic coverage expansion.

Run ./gradlew crapAnalysis to generate reports in build/reports/crap-analysis/. The task depends on jacocoAggregateReport and will run tests and generate coverage automatically if needed. No additional dependencies or configuration required, fully backward compatible, and only runs when explicitly called. This identifies which code needs attention before refactoring using existing JaCoCo data.

Screenshot 2025-11-24 at 07-47-31 CRAP Score Analysis Report Screenshot 2025-11-24 at 07-47-23 CRAP Score Analysis Report Screenshot 2025-11-24 at 07-47-42 CRAP Score Analysis Report

Add CRAP Score Analysis Task for Test Coverage Prioritization

This PR adds a Gradle task that generates prioritized reports identifying which code poses the highest risk when modified. CRAP (Change Risk Anti-Patterns) combines cyclomatic complexity and test coverage to quantify modification risk using the formula CRAP = complexity² × (1 - coverage)³ + complexity. Methods with CRAP > 30 are high-risk and should either have comprehensive tests added or be refactored to reduce complexity before modification. Methods with complexity > 30 cannot achieve CRAP < 30 even with 100% test coverage and must be refactored. Traditional coverage metrics treat all uncovered code equally, but a simple getter with 0% coverage carries far less risk than complex business logic with 0% coverage.

The task parses existing JaCoCo XML reports and generates an interactive HTML report showing methods ranked by CRAP score, package-level statistics for broad coverage planning, and color-coded risk indicators. It exports CSV for custom analysis and prints a console summary showing the top 10 highest-CRAP methods and packages with the most untested complexity. Before modifying legacy code, run the analysis to check CRAP scores. CRAP < 10 indicates relatively safe code to modify. CRAP 10-30 requires adding tests before major changes. CRAP > 30 requires either comprehensive tests to bring the score below 30, or refactoring if complexity exceeds 30. The HTML report includes a usage guide and the Packages Overview tab identifies entire packages with high uncovered complexity for systematic coverage expansion.

Run ./gradlew crapAnalysis to generate reports in build/reports/crap-analysis/. The task depends on jacocoAggregateReport and will run tests and generate coverage automatically if needed. No additional dependencies or configuration required, fully backward compatible, and only runs when explicitly called. This identifies which code needs attention before refactoring using existing JaCoCo data.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants