具有代码覆盖率的单元测试,结果不包括给定类涉及的所有方法 [英] Unit testing with code coverage, result does not include all methods involved for a given class

查看:168
本文介绍了具有代码覆盖率的单元测试,结果不包括给定类涉及的所有方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚在VS 2015 Enterprise(试用版)中进行了测试,所选测试的代码覆盖率.

Just been testing with VS 2015 enterprise (trial), Code coverage for Selected Tests.

我的问题是,代码覆盖率结果"视图未包含受测给定类的所有方法.  即使方法是由单元测试明确调用的.

My problem is that a the Code Coverage Results view does not include all methods for a given class under test.  Even if methods explicitly are called by unit tests.

如果我为那些确实显示在类(全局类+类)下面的方法打开类,我确实会获得预期的覆盖率和着色.

I do get expected coverage and coloring if I open class for those methods that do show up below the class (Global Classes + class).

我在测试中遇到的大多数类都遇到相同的问题,即那些显示在类下面的方法具有预期的颜色,但是那些未显示的方法则根本没有颜色.  由于报告中似乎缺少很多我的代码,因此覆盖范围 部分似乎不太可靠.

I see the same problem with most of my classes hit by tests, i.e. those methods showing up below class have the expected coloring, but those not showing up have no coloring at all.  As a lot of my code seems to be missing from reports, the coverage part seems rather unreliable.

有什么主意吗?

运行不受管理的C ++,调试,无优化,M​​STest单元测试.

Running unmanaged C++, debug, no optimizations, MSTest unit tests.

项目包含约700个课程

Project contains ~700 classes

谢谢

Hakon

推荐答案

Hakon,

Hi Hakon,

根据您的描述,我创建了一个示例非托管C ++项目,并使用Test Explorer来分析其代码覆盖率.我发现示例项目中的所有方法均已涵盖.

According to your description, I create a sample unmanaged C++ project and using Test Explorer to analysis its code coverage. I find all the method in my sample project is coveraged.

在您遇到的情况下,请检查您的方法是否有任何测试失败以及分支中是否存在某些分支,这可能会导致部件代码未涵盖在内.

In your situation, please check whether there has any test failed and there has some branch in your method, which can cause part code is not coveraged.

此外,请共享一个示例项目和一些屏幕截图,以帮助重现您的问题并检查测试项目中发生了什么.

In addition, please share a sample project and some screenshots to help use reproduce your problem and check what happened in your test project.

最好的问候,
Weiwei

 Best Regards,
Weiwei


这篇关于具有代码覆盖率的单元测试,结果不包括给定类涉及的所有方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆