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
-merge开发者_StackOverflowbyhash
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
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
精彩评论