This project has moved. For the latest updates, please go here.
1

Closed

Total Lines metric incorrect when file contains multiple classes

description

When a file contains multiple classes, the covered/coverable/uncovered metrics are correctly reported for each class. However, the total lines metric for each class is the total lines of the file. This results in the total lines metric for the report being incorrect.

For example, if we have a file, classes.cs, which contains classes A, B and C, each with 10 lines, then we expect the following total lines metrics:
A => 10
B => 10
C => 10
Report => 30

Instead, the metrics are as follows:
A => 30
B => 30
C => 30
Report => 90

If you need any more information, please let me know. This was seen with Report Generator version 2.0.4.
Closed Jan 19, 2015 at 3:06 PM by danielpalme

comments

danielpalme wrote Jan 19, 2015 at 2:03 PM

I think this can't be fixed easily.
  • You could calculate the start and end line of a C# class with NRefactory, but how should F# code be handled (ReportGenerator supports this too)?
  • How should using statements and namespaces be counted?
using A;
using B;

namespace Foo
{
  public class Bar { ... }
  public class Baz { ... }
}
  • Currently files are counted several times. But the sum of all classes is equal to the total lines of code. If I change the code in a way that each file is only counted once, this is no longer true and might cause confusion as well.
  • The metric Total lines is not that important. Coverable lines and Covered lines are much more important and these number are correct.
I don't see a proper way to fix this issue and I think I won't do anything about it.
When someone places several classes in single file, then one has to live with this.

kbremner wrote Jan 19, 2015 at 2:37 PM

I understand that this is really an issue born out of bad practice and that the real answer is to not put classes in the same file.

I agree that a solution could be complicated and cause confusion without much gain. Thanks for taking a look at this issue.

kbremner wrote Jan 19, 2015 at 2:38 PM

I understand that this is really an issue born out of bad practice and that the real answer is to not put classes in the same file.

I agree that a solution could be complicated and cause confusion without much gain. Thanks for taking a look at this issue.

wrote Jan 19, 2015 at 3:06 PM