-
-
Notifications
You must be signed in to change notification settings - Fork 46
What is the definition of 'coverable'? #183
-
Hello,
I'm working on a thesis which uses this tool. I really appreciate the time and effort spent developing it. I was wondering if a coverable line was a concept defined by FineCodeCoverage or by Coverlet and OpenCover and simply given a nice gui home with FCC. Is it best to pour through source code to see how it is determined? I'm trying to explain in my paper what defines the denominator of the code covered percentage.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 2 replies
-
I assume that you mean Coverable lines defined in the Summary tab.
This name is provided by https://github.com/danielpalme/ReportGenerator from a Cobertura file.
Coverlet ( Cobertura ) and OpenCover generate different types of report and these are transformed into a Cobertura file.
For instance
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Win32;
using System;
namespace FCC_Issue_167
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
// Create a RegistryKey, which will access the HKEY_USERS
// key in the registry of this machine.
RegistryKey rk = Registry.Users;
// Print out the keys.
PrintKeys(rk);
}
private void PrintKeys(RegistryKey rkey)
{
// Retrieve all the subkeys for the specified key.
String[] names = rkey.GetSubKeyNames();
int icount = 0;
Console.WriteLine("Subkeys of " + rkey.Name);
Console.WriteLine("-----------------------------------------------");
// Print the contents of the array to the console.
foreach (String s in names)
{
Console.WriteLine(s);
// The following code puts a limit on the number
// of keys displayed. Comment it out to print the
// complete list.
icount++;
if (icount >= 10)
break;
}
}
}
}
OpenCover generates
<?xml version="1.0" encoding="utf-8"?>
<CoverageSession xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="4.7.922.0">
<Summary numSequencePoints="20" visitedSequencePoints="19" numBranchPoints="4" visitedBranchPoints="3" sequenceCoverage="95" branchCoverage="75" maxCyclomaticComplexity="3" minCyclomaticComplexity="1" maxCrapScore="3.00" minCrapScore="1" visitedClasses="1" numClasses="1" visitedMethods="2" numMethods="2" />
<Modules>
<Module hash="17-CD-54-4B-BC-4B-F8-E9-B9-A5-83-07-C6-64-9B-FC-07-9D-94-C8">
<Summary numSequencePoints="20" visitedSequencePoints="19" numBranchPoints="4" visitedBranchPoints="3" sequenceCoverage="95" branchCoverage="75" maxCyclomaticComplexity="3" minCyclomaticComplexity="1" maxCrapScore="3.00" minCrapScore="1" visitedClasses="1" numClasses="1" visitedMethods="2" numMethods="2" />
<ModulePath>C:\Users\tonyh\source\repos\FCC_Issue_167\FCC_Issue_167\bin\Debug\fine-code-coverage\build-output\FCC_Issue_167.dll</ModulePath>
<ModuleTime>2021年08月19日T16:26:39.9052773Z</ModuleTime>
<ModuleName>FCC_Issue_167</ModuleName>
<Files>
<File uid="1" fullPath="C:\Users\tonyh\source\repos\FCC_Issue_167\FCC_Issue_167\UnitTest1.cs" />
</Files>
<Classes>
<Class>
<Summary numSequencePoints="20" visitedSequencePoints="19" numBranchPoints="4" visitedBranchPoints="3" sequenceCoverage="95" branchCoverage="75" maxCyclomaticComplexity="3" minCyclomaticComplexity="1" maxCrapScore="3.00" minCrapScore="1" visitedClasses="1" numClasses="1" visitedMethods="2" numMethods="2" />
<FullName>FCC_Issue_167.UnitTest1</FullName>
<Methods>
<Method visited="true" cyclomaticComplexity="1" nPathComplexity="0" sequenceCoverage="100" branchCoverage="100" crapScore="1" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
<Summary numSequencePoints="4" visitedSequencePoints="4" numBranchPoints="1" visitedBranchPoints="1" sequenceCoverage="100" branchCoverage="100" maxCyclomaticComplexity="1" minCyclomaticComplexity="1" maxCrapScore="1" minCrapScore="1" visitedClasses="0" numClasses="0" visitedMethods="1" numMethods="1" />
<MetadataToken>100663297</MetadataToken>
<Name>System.Void FCC_Issue_167.UnitTest1::TestMethod1()</Name>
<FileRef uid="1" />
<SequencePoints>
<SequencePoint vc="1" uspid="1" ordinal="0" offset="0" sl="12" sc="9" el="12" ec="10" bec="0" bev="0" fileid="1" />
<SequencePoint vc="1" uspid="2" ordinal="1" offset="1" sl="15" sc="13" el="15" ec="45" bec="0" bev="0" fileid="1" />
<SequencePoint vc="1" uspid="3" ordinal="2" offset="7" sl="18" sc="13" el="18" ec="27" bec="0" bev="0" fileid="1" />
<SequencePoint vc="1" uspid="4" ordinal="3" offset="15" sl="19" sc="9" el="19" ec="10" bec="0" bev="0" fileid="1" />
</SequencePoints>
<BranchPoints />
<MethodPoint xsi:type="SequencePoint" vc="1" uspid="1" ordinal="0" offset="0" sl="12" sc="9" el="12" ec="10" bec="0" bev="0" fileid="1" />
</Method>
..................................
This is transformed to Cobertura - lines-valid
?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage line-rate="0.9411764705882353" branch-rate="0.5" lines-covered="16" lines-valid="17" branches-covered="1" branches-valid="2" complexity="4" version="0" timestamp="1629880030">
<sources />
<packages>
<package name="FCC_Issue_167" line-rate="0.9411764705882353" branch-rate="0.5" complexity="4">
<classes>
<class name="FCC_Issue_167.UnitTest1" filename="C:\Users\tonyh\source\repos\FCC_Issue_167\FCC_Issue_167\UnitTest1.cs" line-rate="0.9411764705882353" branch-rate="0.5" complexity="1">
<methods>
<method name="TestMethod1" signature="()" line-rate="1" branch-rate="1" complexity="1">
<lines>
<line number="12" hits="1" branch="false" />
<line number="15" hits="1" branch="false" />
<line number="18" hits="1" branch="false" />
<line number="19" hits="1" branch="false" />
</lines>
</method>
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes this is what I mean, but I'm still struggling to explain what makes a line coverable. Is a coverable line a line of code which can be executed/evaluated at runtime? what makes the first line of a method uncoverable and the opening bracket coverable?
Beta Was this translation helpful? Give feedback.
All reactions
-
To understand fully you will need to research
OpenCover and sequence points and how ReportGenerator transforms this to Cobertura
Coverlet is already Cobertura.
I don't know the finer details.
what makes the first line of a method uncoverable and the opening bracket coverable?
In the image above, lines with whitespace are not coverable. As per the opening and closing bracket, consider a method with no code - we still want to know if has been executed.
Beta Was this translation helpful? Give feedback.