0

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:

Windows 7 32bit Report

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

Windows Server 64bit Report

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

Community
  • 1
  • 1
Jack
  • 2,153
  • 5
  • 28
  • 43
  • The latest version of OpenCover both 32 and 64 share the same CLSID - have both 32 and 64 versions been registered? – Shaun Wilde Aug 15 '11 at 14:22
  • Yes they've both been registered using regsvr32 – Jack Aug 15 '11 at 14:45
  • Could you supply the command line you are using to launch opencover and moles at the same time and other useful instructions, so that I can replicate. – Shaun Wilde Aug 16 '11 at 00:11
  • I've added this to the question - hopefully it will help you reproduce the problem. – Jack Aug 16 '11 at 09:07

1 Answers1

0

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

Shaun Wilde
  • 8,228
  • 4
  • 36
  • 56
  • I've given this a try but to no avail - I'm running the build from a `build.proj` file, to which I added `` just before `` but this did not seem to make a difference. – Jack Aug 25 '11 at 08:47
  • 1
    Are you running nant? If so you should use the setenv task to set environment variables for that process and all child processes. When you use exec, it runs that command in a child process and it will not be picked up by the next child process; this is how I understand it. – Shaun Wilde Aug 25 '11 at 09:52
  • I'm running MSBuild, but I suppose there must be an equivalent to `setenv`. I'll have an experiment and get back to you. – Jack Aug 25 '11 at 11:17
  • I don't think msbuild can do that without your own custom msbuild task. Could you instead call a command file (.bat/.cmd) that does the set operation and then call opencover? – Shaun Wilde Aug 25 '11 at 11:51
  • That sounds like it might work... I've just spotted a System Environment Variables box in the bamboo build configuration so it might work if I put it there. If not I'll try the batch file method. – Jack Aug 25 '11 at 12:59
  • That worked - thanks once again for your help and patience Shaun! – Jack Aug 25 '11 at 13:58