NCover 1.5.8,带有 Moles/Pex 和 NUnit

发布于 2024-12-22 03:12:45 字数 2884 浏览 1 评论 0原文

我无法让以下内容一起工作。

  • NCover 1.5.8(随 TestDriven.NET 附带的版本)
  • NUnit 2.5(随 TestDriven.NET 附带的版本)
  • Moles 和 Pex

我正在使用 Windows 7 x64 和 .NET 4.0 Pex 和 Moles 测试库

我尝试遵循提示来自 this 类似的问题(关于获取Moles 与 MSTest 一起使用)和相关链接。感谢 这个答案,我确实设法让 Moles 和 NUnit 一起工作,但我无法让它与 NCover 一起工作。

这是一个批处理文件。

:: Some paths
:: ==========
set NCoverPath=C:\Program Files (x86)\TestDriven.NET 3\NCover\1.5.8
set NUnitPath=C:\Program Files (x86)\TestDriven.NET 3\NUnit\2.5
set MolesPath=C:\Program Files\Microsoft Moles\bin

:: Some environment variables
:: ==========================
::  (I've tried every combination I can think of here...)
set ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler
set COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler   
set COR_PROFILER={3FB1CC1E-1C17-4A37-9C18-BF3DB8F10E46}
set CLRMONITOR_EXTERNAL_PROFILERS={3FB1CC1E-1C17-4A37-9C18-BF3DB8F10E46}
:: (Note 3FB1CC1E-1C17-4A37-9C18-BF3DB8F10E46 is the CLSID of NCoverLib.dll 1.5.8.
:: Use {9721F7EB-5F92-447c-9F75-79278052B7BA} instead for NCover 3.x or later)

:: Call NCover
:: ===========
:: Here is the main call to NCover/Moles.Runner/NUnit-Console 

"%NCoverPath%\ncover.console.exe" ^
  //pm moles.runner.exe ^
  //ea "moles.runner;mscorlib.Moles" ^
  //reg ^
    "%MolesPath%\moles.runner.exe" "Pex.Tests.dll" ^
      /runner:"%NUnitPath%\NUnit-console.exe"

这是我得到的输出:

NCover.Console v1.5.8 - Code Coverage Analysis for .NET - http://ncover.org
Copyright (c) 2004-2006 Peter Waldschmidt

Command: C:\Program Files\Microsoft Moles\bin\moles.runner.exe
Command Args: ".\Pex.Tests.dll" "/runner:C:\Program Files (x86)\TestDriven.NET 3\NUnit\2.5\NUnit-console.exe"
Working Directory:
Assemblies:
Coverage Xml: Coverage.Xml
Coverage Log: Coverage.Log

Waiting for profiled application to connect...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
NUnit version 2.5.5.10112
Copyright (C) 2002-2009 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment -
   OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
  CLR Version: 4.0.30319.239 ( Net 4.0 )

ProcessModel: Default    DomainUsage: Single
Execution Runtime: net-4.0
.................................
Tests run: 33, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0 seconds
  Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0

Connected
Profiled process terminated. Profiler connection not established.

它返回错误代码 1,我的覆盖率文件包含所有测试名称,但覆盖率为零。

I'm having trouble getting the following to work together.

  • NCover 1.5.8 (the version shipped with TestDriven.NET)
  • NUnit 2.5 (the version shipped with TestDriven.NET)
  • Moles and Pex

I'm using Windows 7 x64 with a .NET 4.0 Pex and Moles test library

I have tried to follow tips from this similar question (about getting Moles to work with MSTest) and related links. I did manage to get Moles and NUnit to work together thanks to this answer, but I cannot get it to work with NCover.

Here's a batch file.

:: Some paths
:: ==========
set NCoverPath=C:\Program Files (x86)\TestDriven.NET 3\NCover\1.5.8
set NUnitPath=C:\Program Files (x86)\TestDriven.NET 3\NUnit\2.5
set MolesPath=C:\Program Files\Microsoft Moles\bin

:: Some environment variables
:: ==========================
::  (I've tried every combination I can think of here...)
set ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler
set COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler   
set COR_PROFILER={3FB1CC1E-1C17-4A37-9C18-BF3DB8F10E46}
set CLRMONITOR_EXTERNAL_PROFILERS={3FB1CC1E-1C17-4A37-9C18-BF3DB8F10E46}
:: (Note 3FB1CC1E-1C17-4A37-9C18-BF3DB8F10E46 is the CLSID of NCoverLib.dll 1.5.8.
:: Use {9721F7EB-5F92-447c-9F75-79278052B7BA} instead for NCover 3.x or later)

:: Call NCover
:: ===========
:: Here is the main call to NCover/Moles.Runner/NUnit-Console 

"%NCoverPath%\ncover.console.exe" ^
  //pm moles.runner.exe ^
  //ea "moles.runner;mscorlib.Moles" ^
  //reg ^
    "%MolesPath%\moles.runner.exe" "Pex.Tests.dll" ^
      /runner:"%NUnitPath%\NUnit-console.exe"

And this is the output I get:

NCover.Console v1.5.8 - Code Coverage Analysis for .NET - http://ncover.org
Copyright (c) 2004-2006 Peter Waldschmidt

Command: C:\Program Files\Microsoft Moles\bin\moles.runner.exe
Command Args: ".\Pex.Tests.dll" "/runner:C:\Program Files (x86)\TestDriven.NET 3\NUnit\2.5\NUnit-console.exe"
Working Directory:
Assemblies:
Coverage Xml: Coverage.Xml
Coverage Log: Coverage.Log

Waiting for profiled application to connect...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
NUnit version 2.5.5.10112
Copyright (C) 2002-2009 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment -
   OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
  CLR Version: 4.0.30319.239 ( Net 4.0 )

ProcessModel: Default    DomainUsage: Single
Execution Runtime: net-4.0
.................................
Tests run: 33, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0 seconds
  Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0

Connected
Profiled process terminated. Profiler connection not established.

It returns error code 1 and my coverage files contain all the test names but with zero coverage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟沫凡尘 2024-12-29 03:12:46

经过多次尝试和错误,我找到了一个有效的组合。

  • 唯一需要的环境设置是 COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler (设置上述任何其他设置都会导致 NCover 失败)
  • 使用 moles.runner.x86.exe (而不是 moles.runner.exe),但使用nunit-console.exe,而不是(nunit-console-x86.exe)
  • 您可以选择使用多个 /args 参数为 nunit 指定其他参数,例如 /args="/domain= None" /args="/xml:MyOutput.xml"
  • 不要忘记将 Microsoft.Moles.NUnit.dll 复制到 NUnit 的 addins 子目录。

请参阅下面的更正批处理文件。

:: Some paths
:: ==========
set NCoverPath=C:\Program Files (x86)\TestDriven.NET 3\NCover\1.5.8
set NUnitPath=C:\Program Files (x86)\TestDriven.NET 3\NUnit\2.5
set MolesPath=C:\Program Files\Microsoft Moles\bin
set PexPath=C:\Program Files\Microsoft Pex\bin

:: Important!
set COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler   

:: Here is the main call to NCover/Moles.Runner/NUnit-Console 

"%NCoverPath%\ncover.console.exe" ^
  //pm moles.runner.x86.exe ^
  //ea "moles.runner;mscorlib.Moles" ^
  //reg ^
    "%MolesPath%\moles.runner.x86.exe" "Pex.Tests.dll" ^
      /runner:"%NUnitPath%\NUnit-console.exe"

测试运行,退出代码为零,并生成覆盖文件。

实际上,如果您不需要 NUnit 输出文件,您可以使用 pex.x86.exe 执行相同的操作,如下所示:

"%NCoverPath%\ncover.console.exe" 
  //pm pex.x86.exe 
  //ea "mscorlib.Moles" 
  //reg ^
    "%PexPath%\pex.x86.exe" "%TestAssemblyPath%\Pex.Tests.dll" /nor /ftf

测试运行,退出代码为零并生成覆盖率文件。

After much trial and error I found a combination which works.

  • The only environment setting necessary is COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler (setting any of the others mentioned above will cause NCover to fail)
  • Use moles.runner.x86.exe (instead of moles.runner.exe), but use nunit-console.exe, not (nunit-console-x86.exe)
  • You can optionally specify additional args to nunit by using multiple /args parameters, e.g., /args="/domain=None" /args="/xml:MyOutput.xml"
  • Don't forget to copy Microsoft.Moles.NUnit.dll to the addins subdirectory of NUnit.

See below for the corrected batch file

:: Some paths
:: ==========
set NCoverPath=C:\Program Files (x86)\TestDriven.NET 3\NCover\1.5.8
set NUnitPath=C:\Program Files (x86)\TestDriven.NET 3\NUnit\2.5
set MolesPath=C:\Program Files\Microsoft Moles\bin
set PexPath=C:\Program Files\Microsoft Pex\bin

:: Important!
set COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler   

:: Here is the main call to NCover/Moles.Runner/NUnit-Console 

"%NCoverPath%\ncover.console.exe" ^
  //pm moles.runner.x86.exe ^
  //ea "moles.runner;mscorlib.Moles" ^
  //reg ^
    "%MolesPath%\moles.runner.x86.exe" "Pex.Tests.dll" ^
      /runner:"%NUnitPath%\NUnit-console.exe"

The tests run, the exit code is zero and the coverage files are generated.

Actually, if you don't need the NUnit output files, you can do the same with pex.x86.exe as follows:

"%NCoverPath%\ncover.console.exe" 
  //pm pex.x86.exe 
  //ea "mscorlib.Moles" 
  //reg ^
    "%PexPath%\pex.x86.exe" "%TestAssemblyPath%\Pex.Tests.dll" /nor /ftf

The tests run, the exit code is zero and the coverage files are generated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文