未覆盖 x64 Windows Server 2003 上的 Moles 测试
由于某种原因,OpenCover 未涵盖在 Windows Server 2003(64 位)上使用 Moles 进行的测试。我提出了一个 类似问题,它在我的 32 位 Windows 上解决了这个问题7 机器上,但由于某种原因在 Windows Server 机器上设置环境变量并没有什么区别。
CLRMONITOR_EXTERNAL_PROFILERS: 1542C21D-80C3-45E6-A56C-A9C1E4BEB7B8
x64 探查器是否有不同的 CLSID?或者这可能是另一个问题?
重现步骤
使用三种方法在 Visual Studio 中创建一个新项目:
public int method1()
{
return 1;
}
public int method2()
{
return 2;
}
public int method3()
{
return 3;
}
接下来创建一个测试项目,如下所示:
[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);
}
为了使上述内容能够编译,您需要通过右键单击 ConsoleApplication2 引用并选择“添加 Moles”来“添加 Moles 程序集”集会”。
使用以下命令运行 OpenCover:
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。
预期结果
如果成功(如在我的 32 位 Windows 7 计算机上),报告应显示已覆盖的 method3(在 method2Test 中调用),如下所示:
但是,在 64 位 Windows Server 上运行时,结果如下所示:
在这两种情况下,所有测试均通过,但在 64 位 Windows Server 上使用 Moles 时未获取覆盖范围信息。
我希望这可以更清楚地解释问题 - 如果您需要更多信息,请告诉我。
谢谢,杰克
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
时得到了您的结果,
我按照您的指示操作,当我使用set CLRMONITOR_EXTERNAL_PROFILERS=1542C21D-80C3-45E6-A56C-A9C1E4BEB7B8
但是当我将其更改为
set 时,我得到了所需的覆盖结果CLRMONITOR_EXTERNAL_PROFILERS={1542C21D-80C3-45E6-A56C-A9C1E4BEB7B8}
注意:使用大括号 - 这是表达 GUID 的常用方式
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