NCover support with Moles

2019-02-27 21:05发布

问题:

In our project we use NCover to measure our code coverage. If we measure tests which uses Moles the code coverage for those classes are not measured (0%). This has something to do with both Moles and NCover using the .NET profiler. After some searching on the internet I tried the following in command prompt without any result:

set COR_PROFILER={3FB1CC1E-1C17-4A37-9C18-BF3DB8F10E46} moles.runner.exe /pi:Dispatch /r:"C:\Program Files\NCover\NCover.Console.exe" "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe" /args:/testcontainer:..\Bin\TestLib.dll"

The number behind the COR_PROFILER is the NCover.Lib.x86.dll GUID which I previously registered with regsvr. Also adding COR_ENABLE_PROFILING=1 as env.var doesn't help.

Is there anyone who got this profiler chaining working or has experience with .NET profiler chaining?

回答1:

I dug around and found a way to use NCover in at least one simple example using Moles context. Check out this thread: http://www.ncover.com/forum/show_topic?id=1191



回答2:

Ruud,

Unfortunately, Moles and NCover are incompatible at this time. The problem lies in the fact that NCover sets up some environment vars, which Moles subsequently resets for its own use during the profiling session. It's definitely something that needs to be tackled. You might try asking the folks at Microsoft to consider a workaround for this issue.



回答3:

Have you tried the CLRMONITOR_EXTERNAL_PROFILERS environment variable?

set CLRMONITOR_EXTERNAL_PROFILERS={3FB1CC1E-1C17-4A37-9C18-BF3DB8F10E46}

And then run ncover to call mstest as normal you would otherwis

I used this technique successfully with OpenCover see No Coverage for Moles Tests on x64 Windows Server 2003



标签: moles