VS2008:具有代码覆盖率的单元测试不适用于 /CLR
我正在尝试在 VS2008 中为使用 /clr 编译的 C++/CLI DLL(不是 /clr:safe 或 /clr:pure - 它必须是/clr 因为它使用 MFC)。
单元测试工作完美,但覆盖信息仅在我使用 /clr:safe 或 /clr:pure 编译时才有效。 对于 /clr,代码覆盖率结果窗口显示以下消息:
生成空结果:没有 使用了仪器二进制文件。 看着 任何测试运行详细信息 仪器问题。
我也尝试过“越野”,但是当我加载覆盖文件时进入VS,它也包含空结果。
令人烦恼的是,我找不到任何地方具体说明代码覆盖率是否适用于 /CLR,所以我只能自己尝试一下。
如果它应该有效,任何人都可以看到我在这里做错了什么吗?
[文件]->[新建]->[项目]
选择类库,输入MyProj作为项目名称,单击“确定”
右键单击MyProj项目,选择[属性]
选择【配置属性】->【常规】
确保“公共语言运行时支持”设置为 /CLR
将此代码添加到 Class1:
public:
static int calc() { return 69; }
构建解决方案
[测试]->[新测试]->[单元测试],单击“确定”,单击“创建”
将此代码添加到 TestMethod1:
Assert::AreEqual(MyProj::Class1::calc(), 69);
右键单击 TestProject1 项目,选择 [References]
点击“添加新参考”
在“Projects”选项卡中选择MyProj,单击“确定”,再次单击
“确定”[测试]->[编辑测试运行配置]->[本地测试运行]
选择[代码覆盖率]
检查MyProj.dll,点击应用,点击关闭
[测试]->[运行]->[解决方案中的所有测试]
测试结果窗口显示 TestMethod1 已通过.
代码覆盖率结果窗口显示以下消息:
生成空结果:没有 使用了仪器二进制文件。 看着 任何测试运行详细信息 仪器问题。
右键单击MyProj项目,选择[属性]
选择【配置属性】->【常规】
将“公共语言运行时支持”更改为/CLR:SAFE或/CLR:PURE,单击“确定”
构建解决方案
[测试]->[运行]->[全部解决方案中的测试]
测试结果窗口显示 TestMethod1 已通过。
代码覆盖率结果窗口现在显示正确的覆盖率信息。
I'm trying to set up unit testing with code coverage in VS2008, for a C++/CLI DLL which is compiled with /clr (not /clr:safe or /clr:pure - it has to be /clr because it uses MFC).
The unit tests work perfectly but the coverage information only works if I compile with /clr:safe or /clr:pure. For /clr the Code Coverage Results window shows the following message:
Empty results generated: none of the
instrumented binary was used. Look at
test run details for any
instrumentation problems.
I've also tried "going offroad" but when I load the coverage file into VS, it also contains empty results.
Annoyingly I can't find anywhere that specifically says whether Code Coverage works with /CLR, so I just had to try it myself.
If it should work, can anyone see what I'm doing wrong here?
[File]->[New]->[Project]
Select Class Library, enter MyProj as the project name, click OK
Right-click on MyProj project, select [Properties]
Select [Configuration Properties]->[General]
Ensure "Common Language Runtime support" is set to /CLR
Add this code to Class1:
public:
static int calc() { return 69; }
Build solution
[Test]->[New Test]->[Unit Test], click OK, click Create
Add this code to TestMethod1:
Assert::AreEqual(MyProj::Class1::calc(), 69);
Right-click on TestProject1 project, select [References]
Click "Add New Reference"
Select MyProj in the "Projects" tab, click OK, click OK again
[Test]->[Edit Test Run Configuration]->[Local Test Run]
Select [Code Coverage]
Check MyProj.dll, click Apply, click Close
[Test]->[Run]->[All Tests in Solution]
The Test Results window shows TestMethod1 has passed.
The Code Coverage Results window shows the following message:
Empty results generated: none of the
instrumented binary was used. Look at
test run details for any
instrumentation problems.
Right-click on MyProj project, select [Properties]
Select [Configuration Properties]->[General]
Change "Common Language Runtime support" to /CLR:SAFE or /CLR:PURE, click OK
Build solution
[Test]->[Run]->[All Tests In Solution]
The Test Results window shows TestMethod1 has passed.
The Code Coverage Results window now shows correct coverage information.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于 http://msdn.microsoft.com/en-us/library/ ms182534.aspx
1-项目必须处于调试状态
2.-在项目属性中必须选择 x 86 平台。
3 在 GAC 中取消注册正在测试的项目。
Based on http://msdn.microsoft.com/en-us/library/ms182534.aspx
1-project must be in debug
2.-in the project properties you must select x 86 platform.
3 Unregister the project being tested in the GAC.
是的,我认为这一切都必须在 CLR:Safe 项目中才能发挥作用。 我不完全明白为什么,但我和你在同一条船上。
Yeh, I think it all has to be in CLR:Safe project to work. I don't fully understand why, but I'm in the same boat as you.