No Coverage for Moles Tests on x64 Windows Server 2003

本小妞迷上赌 提交于 2019-12-11 15:35:40

问题


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

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

Steps to reproduce

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);
}

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".

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

The 64bit machine equivalent:

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

Run ReportGenerator on the results.xml file.

Expected Results

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:

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

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.

Thanks, Jack


回答1:


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

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

but I got required coverage results when I changed this to

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

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



来源:https://stackoverflow.com/questions/7063851/no-coverage-for-moles-tests-on-x64-windows-server-2003

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!