currently I am trying to get a code coverage with NCover for a MSTest assembly which uses Moles as Isolation framework. After hours of testing NCover does not gather any coverage information. I researched various stackoverflow posts regarding ncover + moles and mstest and the those posts are the base for my execution:
1) I set the following environment variables:
set CLRMONITOR_EXTERNAL_PROFILERS={9721F7EB-5F92-447C-9F75-79278052B7BA}
set ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler
set COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler
Those environment variables helped other users to get the coverage process to work, on my machine those environment settings do not work and/or change the results.
2) This is my command line call of NCover:
"C:\Program Files (x86)\NCover\ncover.console" //pm moles.runner.x86.exe "C:\Program Files (x86)\Microsoft Moles\bin\moles.runner.x86.exe" "[PathToTestDll]" /runner:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe" /afs:"/testcontainer:{0}"
Based on other posts here, i used the moles.runner.x86.exe (with the other moles.runner.exe the tests won't be executed at all).
The setting of the environment variables and the execution of NCover gives me the following output:
NCover Complete Trial v3.4.18.6937 x86 (Administrator)
Copyright (c) 2007 - 2010 Gnoso Inc.
License Key: .....
Registered to Customer #: 12387 for 1 Machine
17 days left in the trial period.
Command: "C:\Program Files (x86)\Microsoft Moles\bin\moles.runner.x86.exe"
Command Args: "C:\hudson\workspace\Nightly Build - WebApp 2011\Web\WebApp2011\main\WebApp2011\WebApp2011.Test\bin\DebugFull\WebApp2011.Test.dll" "/runner:C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe" "/afs:/testcontainer:{0}"
Working Directory:
Assemblies: (All Loaded Assemblies)
******************* Program Output *******************
Process 'moles.runner.x86' [PID 1664] has begun profiling.
Microsoft Moles Runner v0.94.51023.0 -- http://research.microsoft.com/moles -- .NET v4.0.30319
Copyright (c) Microsoft Corporation 2007-2010. All rights reserved.
instrumenting...started
This version of Moles does not support x64/IA64. Moles will restart as x86 process.
(Consider using command-line option /x86 to avoid restart.)
instrumenting...Process 'moles.runner.x86' [PID 2692] has begun profiling.
started
Microsoft (R) Test Execution Command Line Tool Version 10.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Loading C:\hudson\workspace\Nightly Build - WebApp 2011\Web\WebApp2011\main\WebApp2011\WebApp2011.Test\bin\DebugFull\WebApp2011.Test.dll...
Starting execution...
Results Top Level Tests
------- ---------------
...
29/961 test(s) Passed, 923 Error, 9 Failed
Summary
-------
Test Run Error.
Passed 29
Error 923
Failed 9
-----------
Total 961
Results file: c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\TestResults\Administrator_QAALM 2012-09-10 09_13_58.trx
Test Settings: Default Test Settings
Run has the following issue(s):
Warning: Test Run deployment issue: The assembly or module 'System.Web.Mvc' directly or indirectly referenced by the test container 'c:\hudson\workspace\nightly build - webapp 2011\web\webapp2011\main\webapp2011\webapp2011.test\bin\debugfull\webapp2011.test.dll' was not found.
Process 'moles.runner.x86' [PID 2692] has finished profiling.
Process 'moles.runner.x86' [PID 1664] has finished profiling.
***************** End Program Output *****************
Execution Time: 2.313,0822 s
Symbol Coverage: 0,00%
Branch Coverage: 0,05%
Coverage File: c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\coverage.nccov
moles.runner.x86.exe is returning exit code #1
As you see here the tests get executed, but the coverage is not really gathered. Additionally to get the tests executed I hat to copy the QTAgent32.exe to the following path: C:\Program Files (x86)\Microsoft Moles\bin
Do you have any ideas what I could try to get this stuff to work?
UPDATE I just checked the event log and during the test execution i got several application errors:
1) Many NullReferenceExceptions:
(QTAgent32.exe, PID 1692, Thread 12) AgentObject: Exception while loading test adapter: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.TestTools.Execution.TestAdapterManager.CreateAdapter(String adapterTypeName)
at Microsoft.VisualStudio.TestTools.Execution.TestAdapterManager.LoadAndInitAdapter(String adapterTypeName, ITestElement testElement, IRunContext runContext, Boolean shouldPrepare)
at Microsoft.VisualStudio.TestTools.Execution.TestAdapterManager.LoadAdapter(ITestElement testElement, IRunContext runContext, Boolean checkHostAdapter, Boolean shouldPrepare)
at Microsoft.VisualStudio.TestTools.Agent.AgentObject.ExecuteTest(ITestElement test, IResultSink resultSink, TestContext testContext, Boolean loadTest, Boolean forceSynchronousExecution)
2) QTAgent32 Timeout
(QTAgent32.exe, PID 1692, Thread 6) AgentObject: Cleanup: Timeout reached in cleaning up the agent.