---
title: "findbugs中过滤测试类代码"
author: "alin_ass"
date: "2009-10-14T15:55:16Z"
tags: []
categories: ["研发管理"]
slug: "findbugs"
draft: false
lastmod: "2010-05-11T18:04:17Z"
id: 487966
url: "https://alin-ass.iteye.com/blog/487966"
---

由于测试代码的质量和重要程度均比较低，所以在使用findbugs时往往需要跳过它们，一般的web项目工程内常见的测试代码包括单元测试(XXXTest.java)，main方法，示例(XXXSample.java)，过滤这些代码的方法如下：

 

step1.编写filter文件

```
<FindBugsFilter>
    <Match>
      <Method name="main" />
    </Match>
    <Match>
       <Class name="~.*\.*Test" />
    </Match>
    <Match>
       <Class name="~.*\.*Test\$.*" />
    </Match>
     <Match>
       <Class name="~.*\.*Sample" />
    </Match>
    <Match>
       <Class name="~.*\.*Sample\$.*" />
    </Match>

</FindBugsFilter>

```

 

 

step2.在eclipse plugin里添加上文的filter文件

![](http://dl.iteye.com/upload/attachment/156037/8065ffc9-aaef-3888-bbf9-3c1d90915b5e.png)