2

目前我正在尝试使用 NCover 为使用 Moles 作为隔离框架的 MSTest 程序集获取代码覆盖率。经过数小时的测试,NCover 不会收集任何覆盖率信息。我研究了有关 ncover + moles 和 mstest 的各种 stackoverflow 帖子,这些帖子是我执行的基础:

1)我设置了以下环境变量:

set CLRMONITOR_EXTERNAL_PROFILERS={9721F7EB-5F92-447C-9F75-79278052B7BA}
set ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler
set COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler

这些环境变量帮助其他用户使覆盖过程正常工作,在我的机器上,这些环境设置不起作用和/或改变结果。

2)这是我对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}"

根据此处的其他帖子,我使用了 moles.runner.x86.exe(与其他 moles.runner.exe 一起,测试根本不会执行)。

环境变量的设置和 NCover 的执行给了我以下输出:

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

正如您在此处看到的,测试被执行,但并没有真正收集到覆盖率。此外,为了执行测试,我将 QTAgent32.exe 复制到以下路径:C:\Program Files (x86)\Microsoft Moles\bin

你有什么想法我可以尝试让这些东西发挥作用吗?

更新 我刚刚检查了事件日志,在测试执行期间我遇到了几个应用程序错误:

1)许多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 超时

(QTAgent32.exe, PID 1692, Thread 6) AgentObject: Cleanup: Timeout reached in cleaning up the agent.
4

0 回答 0