用于忽略 JUnit 测试的 FindBugs 过滤器文件 [英] FindBugs filter file for ignoring JUnit tests

查看:35
本文介绍了用于忽略 JUnit 测试的 FindBugs 过滤器文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为我的 findbugs ant 脚本设置一个过滤文件,它只扫描 src/* 文件而不扫描 test/* 文件.

I need to set up a filter file for my findbugs ant script that scans only the src/* files and not the test/* files.

在忽略名称中带有 'test' 的任何文件名或包名时检查所有类的语法是什么?

What is the syntax for checking all classes while ignoring any filename or package name with 'test' in the name?

推荐答案

FindBugs 实际上扫描的是编译好的类文件,而不是 sourcePath.如果您将 src/* 和 test/* 文件编译到不同的目录,则可以使用嵌套的 <class...> 元素.

FindBugs is actually scanning the compiled class files, not the sourcePath. If you are compiling your src/* and test/* files to the different directories, you could just use the nested <class...> element.

<findbugs home="${findbugs.dir}" output="xml:withMessages" 
    outputFile="${findbugs.report.xml}" jvmargs="-Xmx256M" 
    effort="max" projectName="${ant.project.name}" 
    auxClasspathRef="findbugs.classpath" 
    sourcePath="${src.dir}">
  <class location="${src.classes.dir}"/>
</findbugs> 

如果 src/* 和 test/* 都编译到单个目录,那将不起作用.在这种情况下,请使用 过滤文件 并排除与测试对应的包或类名.

That won't work if src/* and test/* are both compiled to a single directory. In that case, use a filter file and exclude the packages or class names that correspond to tests.

<findbugs home="${findbugs.dir}" output="xml:withMessages" 
    outputFile="${findbugs.report.xml}" jvmargs="-Xmx256M" 
    effort="max" projectName="${ant.project.name}" 
    auxClasspathRef="findbugs.classpath" 
    sourcePath="${src.dir}"
    excludefilter="exclude.xml">
  <class location="${classes.dir}"/>
</findbugs> 

其中 exclude.xml 看起来像:

<FindBugsFilter>
  <Match>
    <Class name="~.*Test$"/>
  </Match>
  <Match>
    <Package name="~test\..*"/>
  </Match>
</FindBugsFilter>

这篇关于用于忽略 JUnit 测试的 FindBugs 过滤器文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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