本文介绍了x64 Windows Server 2003上的Moles测试没有覆盖范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,OpenCover没有涵盖Windows Server 2003(64位)上使用痣的测试.我提出了一个类似的问题,该问题在我的32位Windows上得以解决7机器,但是由于某些原因,在Windows Server机器上设置环境变量没有任何作用.

For some reason OpenCover is not covering tests using moles on Windows Server 2003 (64bit). I raised a similar question which solved it on my 32bit Windows 7 machine, but for some reason setting the Environment Variable on the Windows Server machine doesn't make a difference.

CLRMONITOR_EXTERNAL_PROFILERS: 1542C21D-80C3-45E6-A56C-A9C1E4BEB7B8

x64探查器是否有其他CLSID?还是这可能是另一个问题?

Is there a different CLSID for the x64 profiler? Or could this be another problem?

使用三种方法在Visual Studio中创建一个新项目:

Create a new project in visual studio with three methods:

public int method1()
{
    return 1;
}

public int method2()
{
    return 2;
}

public int method3()
{
    return 3;
}

接下来创建一个测试项目,如下所示:

Next create a test project like so:

[TestMethod()]
public void method1Test()
{
    // Test without moles
    Program target = new Program();
    int expected = 1;
    int actual = target.method1();
    Assert.AreEqual(expected, actual);
}

[TestMethod()]
[HostType("Moles")]
public void method2Test()
{
    // Test using moles
    ConsoleApplication2.Moles.MProgram.AllInstances.method2 = (instance) => { return 3; };
    Program target = new Program();

    // method3 is only called in this test
    int check = target.method3();
    int actual = target.method2();
    Assert.AreEqual(3, actual);
    Assert.AreEqual(3, check);
}

为使以上内容编译,您将需要添加一个Moles程序集"通过右键单击ConsoleApplication2参考并选择添加Moles程序集".

So that the above compiles, you will need to "Add a Moles Assembly" by right clicking on the ConsoleApplication2 reference and selecting "Add Moles Assembly".

使用以下命令运行OpenCover:

Run OpenCover with the following command:

C:\Program Files\OpenCover>OpenCover.Console.exe
-target:"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe"
-targetdir:"S:\Work\ConsoleApplication2"
-targetargs:"/testcontainer:\"TestProject1\bin\Debug\TestProject1.dll\""
-filter:"+[*]*"
-output:results.xml
-mergebyhash

等效于64位计算机:

C:\Program Files (x86)\OpenCover>OpenCover.Console.exe"
-target:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe"
-targetdir:"S:\Work\ConsoleApplication2"
-targetargs:"/testcontainer:\"TestProject1\bin\Debug\TestProject1.dll\""
-filter:"+[*]*"
-output:results.xml
-mergebyhash

在results.xml文件上运行ReportGenerator.

Run ReportGenerator on the results.xml file.

如果成功(如在我的32位Windows 7计算机上),则报告应显示method3已覆盖(在method2Test中调用),并且看起来像这样:

If successful (as on my 32bit Windows 7 machine) the report should show method3 as covered (it is called in method2Test), and look like this:

但是,在64位Windows Server上运行时,结果如下:

However when run on the 64bit Windows Server, the results look like this:

在这两种情况下,所有测试均通过,但是在64位Windows Server上使用Moles进​​行测试时未获取覆盖率信息.

In both cases all tests pass, but no coverage information is being picked up for the test using Moles on the 64bit Windows Server.

我希望这可以对问题进行更清晰的解释-如果您需要更多信息,请告诉我.

I hope this gives a more clear explanation of the problem - let me know if you need any more information.

谢谢杰克

推荐答案

我按照您的指示进行操作,使用后我得到了您的结果

I followed your instructions and I got your results when I used

设置CLRMONITOR_EXTERNAL_PROFILERS = 1542C21D-80C3-45E6-A56C-A9C1E4BEB7B8

set CLRMONITOR_EXTERNAL_PROFILERS=1542C21D-80C3-45E6-A56C-A9C1E4BEB7B8

但是当我将其更改为

设置CLRMONITOR_EXTERNAL_PROFILERS = {1542C21D-80C3-45E6-A56C-A9C1E4BEB7B8}

set CLRMONITOR_EXTERNAL_PROFILERS={1542C21D-80C3-45E6-A56C-A9C1E4BEB7B8}

注意:用大括号-这是表示GUID的常用方式

NOTE: used braces - which is the usual way of expressing a GUID

这篇关于x64 Windows Server 2003上的Moles测试没有覆盖范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 10:33