Question about NCover and generator methods, possible bug?

Question about NCover and generator methods, possible bug?

Take the following method:

namespace ClassLibrary4
{
    public class ClassToTest
    {
        public static IEnumerable<Int32> Sequence()
        {
            try
            {
                for (Int32 index = 1; index <= 10; index++)
                    yield return index;
            }
            finally
            {
                Debug.WriteLine("Test line");
            }
        }
    }

    [TestFixture]
    public class ClassWithTests
    {
        [Test]
        public void Test()
        {
            foreach (Int32 index in ClassToTest.Sequence())
            {
            }
            Assert.IsTrue(true);
        }
    }
}

if I try to run a unit-test on this, through TestDriven, with Debugging enabled, I can set a breakpoint on the Debug.WriteLine line and see that it stops there.

However, if I run it with coverage, the Debug.WriteLine is flagged as never executed. Is this some part of the things that 1.5.5/1.5.6 has a problem with?

Note that it is not an issue about the DEBUG flag, as I have a much more complex routine in my class library which suffers the same problem, that I can stop the debugger inside the finally block, but NCover seems to think it is never executed.

TestDriven is distributed with a NCover version marked as 1.5.6 so that's what I've used.


Re: Using NCover on a .dll?

Darrell,

What you want to do is profile the nunit-console.exe executable running your unit tests. So the command line at its simplest will look something like this:

ncover.console.exe nunit-console.exe my.tests.dll

As nunit-console will not have .pdb assemblies in the directory, it's own assemblies will not be included in the coverage output. So provided you do have .pdbs for the code being called by your unit tests, that should be the only profiled coverage information you see in the output.


Re: Using NCover on a .dll?

Awesome! Thanks!