如何从EclEmma中的覆盖范围计算中排除类,而又不从覆盖范围本身实际排除它们 [英] How to exclude classes from the coverage calculation in EclEmma without actually excluding them from the coverage itself

查看:117
本文介绍了如何从EclEmma中的覆盖范围计算中排除类,而又不从覆盖范围本身实际排除它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EclEmma来测试方案测试和项目用例测试的覆盖范围。
我有一个Base包,其中包含最通用的类​​和用例测试。覆盖范围如下:

I am using EclEmma to test the coverage of my scenario tests and use case tests on my project. I have a Base package which contains the most general classes and the use case tests. The coverage looks like this:

我做什么想要的是从覆盖率计算中排除用例测试(例如BugReportTest)。但我确实希望考虑其中的测试。我知道如何从覆盖范围中排除整个类,但如果这样做,覆盖率会下降,因为忘记了检查我的代码的哪几行的实际测试。出于隐私原因,这些用例测试确实需要保留在Base程序包中。

What I want is to exclude the use case tests (e.g. BugReportTest) from the coverage calculation. But I do want the tests inside it to be considered. I know how to exclude the entire class from the coverage but if I do that, my coverage % drops because the actual tests that check which lines of my code are tested are forgotten. These use case tests do need to stay in the Base package because of privacy reasons.

推荐答案

出于技术原因,可能有必要从代码覆盖率分析中排除某些类。以下选项将coverage代理配置为从分析中排除某些类别。除了性能优化或技术特殊情况外,通常不需要这些选项。

For technical reasons it might be necessary to exclude certain classes from code coverage analysis. The following options configure the coverage agent to exclude certain classes from analysis. Except for performance optimization or technical corner cases these options are normally not required.


  1. 排除在外:
    执行分析应排除的类名列表。列表条目用冒号(:)
    分隔,并且可以使用通配符(*和?)。 (默认:空)

排除类加载器:应为$的类加载器名称列表b $ b从执行分析中排除。列表条目由
a 冒号(:)分隔,并且可以使用通配符(*和?) 。在与
JaCoCo代码规范冲突的特殊框架的情况下,可能需要使用该选项
,特别是没有
的类加载器有权访问Java运行时类。 (默认值:
sun.reflect.DelegatingClassLoader)

Exclude classloaders: A list of class loader names that should be excluded from execution analysis. The list entries are separated by a colon (:) and may use wildcard characters (* and ?). This option might be required in case of special frameworks that conflict with JaCoCo code instrumentation, in particular class loaders that do not have access to the Java runtime classes. (Default: sun.reflect.DelegatingClassLoader)




警告:请谨慎使用这些选项!无效的输入可能会破坏代码覆盖面启动器的
。也不要使用这些选项来定义
分析的范围。 排除的类别仍将显示为未覆盖



资源链接:



Resource Link:


  1. EclEmma代码覆盖率首选项

  1. EclEmma Code Coverage Preferences






以下示例均指定了相同的包含/排除模式集: / h2>


The following examples all specify the same set of inclusion/exclusion patterns:


  1. < filter includes = com.foo。* excludes = com.foo.test。*,
    com.foo。* Test * />

  2. < filter includes = com.foo。* /> < filter excludes = com.foo.test。*,
    com.foo。* Test * />

  3. < filter value = + com.foo。*,-com.foo.test。*,-com.foo。* Test * />

    < filter excludes = com.foo。* Test * file = myfilters.txt />

    其中myfilters.txt文件包含以下行:

  1. <filter includes="com.foo.*" excludes="com.foo.test.*, com.foo.*Test*" />
  2. <filter includes="com.foo.*" /> <filter excludes="com.foo.test.*, com.foo.*Test*" />
  3. <filter value="+com.foo.*, -com.foo.test.*, -com.foo.*Test*" />
    <filter excludes="com.foo.*Test*" file="myfilters.txt" />
    where myfilters.txt file contains these lines:

-com.foo.test。*
+ com.foo。*



资源链接:



Resource Link:


  1. 覆盖率过滤器

  2. 我确定我所有的类都是使用-g(debug ='true')
    构建的,但是EMMA仍然抱怨缺少调试信息!

  1. Coverage filters
  2. I am certain that all of my classes are built with -g(debug='true') and yet EMMA still complains about missing debug info!






忽略EclEmma中单元测试的代码覆盖率



首选项-> Java->代码覆盖率,并设置仅路径条目匹配 src / main / java 的选项-似乎很好用


Ignore code coverage for unit tests in EclEmma

Preferences->Java->Code Coverage and set the "Only path entries matching" option to src/main/java - seems to work nicely

这篇关于如何从EclEmma中的覆盖范围计算中排除类,而又不从覆盖范围本身实际排除它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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