java 用于忽略 JUnit 测试的 FindBugs 过滤器文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/756523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FindBugs filter file for ignoring JUnit tests
提问by user64133
I need to set up a filter file for my findbugs ant script that scans only the src/* files and not the test/* files.
我需要为我的 findbugs ant 脚本设置一个过滤器文件,它只扫描 src/* 文件而不是 test/* 文件。
What is the syntax for checking all classes while ignoring any filename or package name with 'test' in the name?
检查所有类同时忽略名称中带有“test”的任何文件名或包名的语法是什么?
回答by CoverosGene
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 实际上是扫描编译后的类文件,而不是sourcePath. 如果您将 src/* 和 test/* 文件编译到不同的目录,则可以只使用嵌套<class...>元素。
<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>
That won't work if src/* and test/* are both compiled to a single directory. In that case, use a filter fileand exclude the packages or class names that correspond to tests.
如果 src/* 和 test/* 都编译到单个目录,那将不起作用。在这种情况下,请使用过滤器文件并排除与测试对应的包或类名。
<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>
where exclude.xmllooks like:
哪里exclude.xml看起来像:
<FindBugsFilter>
<Match>
<Class name="~.*Test$"/>
</Match>
<Match>
<Package name="~test\..*"/>
</Match>
</FindBugsFilter>
回答by Slava Imeshev
By the way, it is a good ideato cover unit tests with FindBugs as well. There is no reason for using lower quality standards towards tests. Bugs in test are just that, bugs.
顺便说一句,用 FindBugs 覆盖单元测试也是一个好主意。没有理由对测试使用较低的质量标准。测试中的错误就是这样,错误。
Sure, if you run FindBugs first time, there might be many bug reports, but the bug count will come down overtime if you pay any attention to them.
当然,如果您第一次运行 FindBugs,可能会有很多错误报告,但是如果您对它们有所关注,错误计数会随着时间的推移而下降。

