Constructor Coverage
Constructor Coverage
First, let me say how useful this tool has been for displaying coverage results, especially for very large projects. I use it all the time.
I came across a situation where coverage results seem to go awry. For classes that have multiple constructors and a field that is instantiated on the declaration line, only one constructor is displayed in the coverage summary. Here's a code snippit that has a class that demonstrates this behavior and another that shows the correct results by instead instantiating the object in the constructors:
/// <summary>
/// Demonstrates constructor issue
/// </summary>
public class NCoverExplorerTest1
{
private string[] _testArray = new string[5];
public NCoverExplorerTest1()
{
}
public NCoverExplorerTest1(string stringParam)
{
}
public NCoverExplorerTest1(int intParam)
{
}
}
/// <summary>
/// Demonstrates normal behavior
/// </summary>
public class NCoverExplorerTest2
{
private string[] _testArray;
public NCoverExplorerTest2()
{
_testArray = new string[5];
}
public NCoverExplorerTest2(string stringParam)
{
_testArray = new string[5];
}
public NCoverExplorerTest2(int intParam)
{
_testArray = new string[5];
}
}
I did some testing around this issue and it seems to stem from the first seqpnt in the coverage xml file being common to several methods of the same class and having the same name. When I comment out that seqpnt from all of the method nodes that share the same first line #, each constructor appears separately. Without it commented out, it only displays the coverage for the first constructor listed in the coverage file instead.
Please let me know if you need any more info or want me to send along the demo project I created to illustrate this.
Thanks,
Colin