簡體   English   中英

FindBugs過濾器文件,用於忽略JUnit測試

[英]FindBugs filter file for ignoring JUnit tests

我需要為我的findbugs ant腳本設置一個過濾器文件,它只掃描src / *文件,而不掃描test / *文件。

檢查所有類的語法是什么,同時忽略名稱中帶有'test'的任何文件名或包名?

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 / *編譯為單個目錄,那將無效。 在這種情況下,請使用過濾器文件並排除與測試對應的包或類名。

<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,可能會有很多錯誤報告,但如果你注意它們,那么錯誤計數將會超時。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM