我需要为findbugs ant脚本设置一个过滤器文件,该脚本只扫描src/*文件而不扫描test/*文件。FindBugs过滤器文件忽略JUnit测试
什么是语法检查所有类,而忽略名称中的'测试'的任何文件名或包名称?
我需要为findbugs ant脚本设置一个过滤器文件,该脚本只扫描src/*文件而不扫描test/*文件。FindBugs过滤器文件忽略JUnit测试
什么是语法检查所有类,而忽略名称中的'测试'的任何文件名或包名称?
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>
如果src/*和test/*都被编译到一个目录中,那么这将不起作用。在这种情况下,请使用filter file并排除与测试对应的软件包或类名称。
<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>
顺便说一句,这是一个好主意覆盖单元测试与FindBugs的为好。没有理由使用低质量的标准进行测试。测试中的错误就是这样,错误。
当然,如果你第一次运行FindBugs,可能会有很多bug报告,但是如果你注意到它们的话bug数量会随着时间的推移而降低。
与此相关的问题是您在单元测试中测试错误情况(例如,将null标记为标记@Nonnull的参数) – 2012-09-20 10:55:41
很好的解释...显然我需要开始喝咖啡或什么的。删除了我的答案,这是正确的误导。 – TofuBeer 2009-04-16 16:35:14