Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FindBugs filter file for ignoring JUnit tests

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

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

like image 322
user64133 Avatar asked Apr 16 '09 14:04

user64133


1 Answers

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> 

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> 

where exclude.xml looks like:

<FindBugsFilter>
  <Match>
    <Class name="~.*Test$"/>
  </Match>
  <Match>
    <Package name="~test\..*"/>
  </Match>
</FindBugsFilter>
like image 69
Gene Gotimer Avatar answered Sep 18 '22 16:09

Gene Gotimer