I've been working on implementing OpenCover in a local build of some of the various APIs I work on for the sake of getting a decent testing report structure built for my team. When attempting to run the coverage against my NUnit tests however I've discovered that some of my more important classes are omitted from the report generated and have the visited node for the respective object set to false.
I still receive the proper NUnit results and know that the coverage results I expect are there due to running against Visual Studio's built-in tool to validate also. It's just OpenCover that fails to report correctly.
The common thread in any of these objects going unreported as I've discovered appears to be that they're sealed. I'm guessing that OpenCover is skipping those classes and uses some type of reflection for it's reporting structure, but I haven't had a chance to check out the source to prove this since I'm on a pretty stringent, internal network.
Anybody run into anything similar or have any tips to overcome this issue? I, of course, can't just remove the sealed keyword from my classes since they need it.
Edit* Here's an example I wrote up of something similar:
using System.Text;
using NUnit.Framework;
namespace OpenCover.Sealed.Test
{
using Helpers;
[TestFixture]
public class UtilityTest
{
[Test, Owner("Patrick Ramser")]
public void ConcatTest()
{
Utility utility = Utility.CreateNewUtility();
string concatMsg = utility.Concat
("1:{0} 2:{1} 3:{2}", "FIRST", "SECOND", "THIRD");
Assert.AreEqual
(concatMsg, "1:FIRST 2:SECOND 3:THIRD", "Wrong message returned!");
}
}
}
namespace OpenCover.Sealed.Helpers
{
public sealed class Utility
{
internal Utility()
{
}
public static Utility CreateNewUtility()
{
return new Utility();
}
public string Concat(string message, params string[] lstStrings)
{
StringBuilder builder = new StringBuilder(message);
for (int i = 0; i < lstStrings.Length; i++)
{
builder.Replace("{" + i + "}", lstStrings[i]);
}
return builder.ToString();
}
}
}
When using both NUnit and the new test assembly I simply reference:
D:\exes\OpenCover\OpenCover.Console.exe
-target:"D:\TestRunners\nunit.console.exe"
-targetargs:"/nologo /domain=Single /xml=C:\NUnit\Artifacts\nunit-results.xml
D:\OpenCover.Sealed.Test\bin\Debug\OpenCover.Sealed.Test.dll"
-output:"C:\NUnit\Artifacts\coverage.xml"
-register
-filter:"+[OpenCover.Sealed*]*"
-returntargetcode
There are no spaces or formatting for the batch script I run, I just limited it between lines to make it more readable.
Could internals either pose any issue?