-
-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calculate C.R.A.P. Score from Cobertura file? #641
Comments
For info, here's a snippet: // CoberturaParser.cs
private static void SetMethodMetrics(CodeFile codeFile, IEnumerable<XElement> methodsOfFile)
{
foreach (var method in methodsOfFile)
{
string fullName = method.Attribute("name").Value + method.Attribute("signature").Value;
fullName = ExtractMethodName(fullName, method.Parent.Parent.Attribute("name").Value);
// ... abridged for clarity
if (cyclomaticComplexity.HasValue && coveragePercent.HasValue)
{
// https://testing.googleblog.com/2011/02/this-code-is-crap.html
// CRAP(m) = CC(m)^2 * U(m)^3 + CC(m)
// CC(m) <= Cyclomatic Complexity (e.g. 5)
// U(m) <= Uncovered percentage (e.g. 30% = 0.3)
var uncoveredPercent = (100f - (double)coveragePercent.Value) / 100.0;
var complexity = (double)cyclomaticComplexity.Value;
var crapScore = (Math.Pow(complexity, 3.0) * Math.Pow(uncoveredPercent, 2)) + complexity;
metrics.Insert(0, Metric.CrapScore((decimal)crapScore));
}
// ... abridged for clarity
}
}
|
@rikrak |
I'll put together a PR :-) |
I've submitted a PR. I'm quite new to contributing to OS projects, so let me know if the PR needs adjusting in any way :-) |
Thank you! |
Release 5.2.1 is now available containing the new metric! |
Terrific, I'll check it out tomorrow :-) |
Not so much a bug as a feature request/question.
When processing Cobertura files, would it be possible to also calculate the crap score? Corbertura itself doesn't provide a value for this metric, but it looks possible to calculate it from the Cyclomatic Complexity and Coverage values for each method using:
CRAP(m) = CC(m)^2 * U(m)^3 + CC(m)
Where
CC(m)
= Cyclomatic Complexity (e.g. 5)U(m)
= Uncovered percentage (e.g. 30% = 0.3)I've played about with the code locally and produced a report from cobertura that does this. Just wondering if this is worth working into a PR?
The text was updated successfully, but these errors were encountered: