使用Cobertura从代码覆盖中排除方法 [英] Exclude methods from code coverage with Cobertura

查看:104
本文介绍了使用Cobertura从代码覆盖中排除方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将代码排除在Cobertura覆盖率报告中?我们有一些方法不应该包含在覆盖率报告中,因此不会降低覆盖率数字。

Is there a way to exclude code from inclusion into Cobertura coverage reports? We have some methods that should not be included in the coverage report and therefore not drive down the coverage numbers.

我知道Clover有这样的功能,但我还没有发现类似于Cobertura。

I know that Clover has such a functionality, but I have not found anything similar for Cobertura.

推荐答案

您可以从检测中排除类。然后它们不应出现在报告中。请参阅下面的排除语句。

You can exclude classes from instrumentation. Then they should not appear on reports. See exclude statements below.

您还可以忽略对某些方法的调用。请参阅下面的忽略语句。

You can also ignore calls to some methods. See ignore statement below.

如果您使用的是maven,请参阅 maven插件手册

If you are using maven, see maven plugin manual.

    <configuration>
      <instrumentation>
        <ignores>
          <ignore>com.example.boringcode.*</ignore>
        </ignores>
        <excludes>
          <exclude>com/example/dullcode/**/*.class</exclude>
          <exclude>com/example/**/*Test.class</exclude>
        </excludes>
      </instrumentation>
    </configuration>

对于ant,请参阅这个

<cobertura-instrument todir="${instrumented.dir}">
  <ignore regex="org.apache.log4j.*" />
  <fileset dir="${classes.dir}">
    <include name="**/*.class" />
    <exclude name="**/*Test.class" />
  </fileset>
  <fileset dir="${jars.dir}">
    <include name="my-simple-plugin.jar" />
  </fileset>
</cobertura-instrument>

这篇关于使用Cobertura从代码覆盖中排除方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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