Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.0.7
-
Fix Version/s: 1.0.8
-
Labels:None
-
Environment:Maven 1.0 jcoverage 1.0.5
-
Number of attachments :
Description
First, please excuse me for my poor English.
Maven jcoverage plugins generate an html report using xml data generated by jcoverage.
The overwiew and packages rates are not the sames as with jcoverage alone. This difference is due to the maven plugin algorythm wich ignores the "weight" (number of lines) of the classes.
If a package contains two classes one which contains 200 lines is tested at 80% and an other wich contains 10 lines tested at 0%, the plugin will compute a package rate of 40%, jcoverage alone will compute a rate of 76%.
I have modified the plugin in order to compute the good rates.
Here are the changes :
Coverage.java :
public String getCoveredPercentBranch()
{
double totalLines = 0.00d;
double total = 0.00d;
if (getLineCoverage() > 0.00d)
{
for (Iterator iter = getClasses().iterator(); iter.hasNext(); )
{
Clazz theClass = (Clazz) iter.next();
int classLines = theClass.getLines().size();
double rate = 0;
try
catch(NumberFormatException e)
{ rate = 0; }
total += (rate*classLines);
totalLines += classLines;
}
total /= totalLines;
}
return String.valueOf(total);
}
private double getLineCoverage()
{
double totalLines = 0.00d;
double totalTestedLines = 0.00d;
for (Iterator iter = getClasses().iterator(); iter.hasNext(); )
{
Clazz theClass = (Clazz) iter.next();
int classLines = theClass.getLines().size();
double rate = 0;
try
{ rate = new Double(theClass.getLineRate()).floatValue(); }
catch(NumberFormatException e)
{ rate = 0; }
totalTestedLines += (rate * classLines);
totalLines += classLines;
}
return (totalTestedLines / totalLines);
}
Package.java :
public String getCoveredPercentBranch()
{
double pckgLines = 0.00d;
double total = 0.00d;
if (getLineCoverage() > 0.00d)
{
for (Iterator iter = getClasses().iterator(); iter.hasNext(); )
{
Clazz theClass = (Clazz) iter.next();
int classLines = theClass.getLines().size();
double rate = 0;
try
{ rate = new Double(theClass.getBranchRate()).floatValue(); }
catch(NumberFormatException e)
{ rate = 0; } total += (rate*classLines);
pckgLines += classLines;
}
total /= pckgLines;
}
return String.valueOf(total);
}
private double getLineCoverage()
{
double pckgLines = 0.00d;
double pckgTestedLines = 0.00d;
for (Iterator iter = getClasses().iterator(); iter.hasNext(); )
{
Clazz theClass = (Clazz) iter.next();
int classLines = theClass.getLines().size();
double rate = 0;
try
catch(NumberFormatException e)
{ rate = 0; } pckgTestedLines += (rate * classLines);
pckgLines += classLines;
}
return (pckgTestedLines / pckgLines);
}
May be branches rates could be "weighted" by the number of branches and not by the number of lines.
Thanks, Thomas
Applied. Thanks.