Visual Studio code metrics misreporting lines of code
Posted
by
Ian Newson
on Stack Overflow
See other posts from Stack Overflow
or by Ian Newson
Published on 2012-10-26T10:28:05Z
Indexed on
2012/10/27
11:01 UTC
Read the original article
Hit count: 482
The code metrics analyser in Visual Studio, as well as the code metrics power tool, report the number of lines of code in the TestMethod
method of the following code as 8.
At the most, I would expect it to report lines of code as 3.
[TestClass]
public class UnitTest1
{
private void Test(out string str)
{
str = null;
}
[TestMethod]
public void TestMethod()
{
var mock = new Mock<UnitTest1>();
string str;
mock.Verify(m => m.Test(out str));
}
}
Can anyone explain why this is the case?
Further info
After a little more digging I've found that removing the out
parameter from the Test method and updating the test code causes LOC to be reported as 2, which I believe is correct. The addition of out
causes the jump, so it's not because of braces or attributes.
Decompiling the DLL with dotPeek reveals a fair amount of additional code generated because of the out
parameter which could be considered 8 LOC, but removing the parameter and decompiling also reveals generated code, which could be considered 5 LOC, so it's not simply a matter of VS counting compiler generated code (which I don't believe it should do anyway).
© Stack Overflow or respective owner