NUnitTest failure when using NCover ( version 1.5.4 & 1.5.3

NUnitTest failure when using NCover ( version 1.5.4 & 1.5.3

Hey people,

We currently use NCover to trigger all our unittests, so we can see how much code we cover... But some unittests keep on failing !

When we had a closer look at the code, we were able to run the unittest from within visual studio and with the nunit gui, nunit console options.

But running the tests through NCover, results in failure ! The call for the unittest is : NCover.Console.exe "C:\Program Files\NUnit 2.2.5\bin\nunit-console.exe" "Z:\ADC_QS_NGA\Bin\Debug\NX.Data.UnitTests.Persistency.dll" /noshadow /xml="C:\Temp\NX\Results\TestResults.xml" //w "Z:\ADC_QS_NGA\Bin\Debug" //x "C:\Temp\NX\Results\Coverage.xml"

I think it has something to do with the fact that it are the only tests where we use WeakReferences and force the Garbadge collector to "collect"...

Code snippet from the unittest :


WeakReference weakStudy = new WeakReference(study);

region Execute Code

study = null;

GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect();

endregion




We don't get any error messages, the test just fails and the failure point is indicated at the last }, surrounding the unittest !

Any suggestions ? Greets Glenn


Re: NCover not profiling the dlls loaded using Reflection

Please let us know if this feature is included in the NCover.


Re: NCover not profiling the dlls loaded using Reflection

You need to provide more information such as sample code of what you mean by your reflection dll load. Also the relevant sections form the coverage.log would be handy as well.

NCover will profile any managed code assembly loaded into the current process for which it can find the symbol file. I suspect that in your scenario you either do not have or NCover cannot find the .pdb file for the assembly you are loading.


Re: NCover not profiling the dlls loaded using Reflection

Grant,

NUnitTest.dll --> MyApp.dll

MyApp.dll --> FileLogWriter.dll

MyApp.dll --> DatabaseLogWriter.dll

Based on some parameters it gets the the assembly path of either FileLogWriter.dll or DatabaseLogWriter.dll and creates the instance of type.

Assembly asm = Assembly.LoadFrom(assemblyPath);
 if (asm != null)
 {
     Type t = asm.GetType(typeName);
     if (t != null)
     {
        logWriter = (ILogWriter)Activator.CreateInstance(t, true);
     }
 }   

I have some test cases to test both the dlls and I see them passing, so I am sure both the dlls are loaded but I dont find any entry in the Coverage.log file. I have .pdb files at "assemblyPath" (dlls location) location for both the dlls.

Please let me know what part of Coverage.Log you are interested in because I dont see any entry for any of these two dlls.

Thanks & Regards,

Chandan.


Re: NCover not profiling the dlls loaded using Reflection

Chandan,

I will have to try this myself when I get some time. However in the meantime I would suggest try copying the .pdb files for those dynamically loaded assemblies into the folder your application is launched from. e.g. if you are running unit tests then in the unit test entry point dll folder. I have a suspicion that NCover may only be looking in that folder for the pdbs and not the "assemblyPath" location.


Re: NCover not profiling the dlls loaded using Reflection

Grant,

I found the issue in my code. Its working now and NCover is profiling all the dlls loaded using reflection as well.

Thanks & Regards,

Chandan.


Re: NCover, NUnit & app.config

David,

Exactly what are you calling your "app.config" file and are your NUnit tests in an executable or a .dll? Using which VS.Net version?

If I have "foo.tests.dll" then normally the only "trick" is to have a "foo.tests.dll.config" file (which is your app.config). Calling under NUnit should be the same regardless of whether you do it under NCover or not. What command line are you using?

You could also use the TestDriven.Net add-in (if you are not already) which makes testing with coverage a lot less painful. Alternatively you could try the NCoverExplorer 1.3.5 release (still in beta) which has a GUI for running NCover -the thread is here