白盒静态自动化测试工具:FindBugs使用指南
目 录
1 FINDBUGS介绍
2 在ECLIPSE中安装FINDBUGS插件
3 在ECLIPSE中使用FINDBUGS操作步骤
3.1 打开FindBugs视图
3.2 执行FindBugs任务
4 配置FINDBUGS
4.1 Run Automatically开关
4.2 Detector Configuration选择项
4.3 Minimum priority to report选择项
4.4 Report bug categories选择项
5 Ant 使用简介
6 总结
1 FindBugs介绍
FindBugs是一款Java静态代码分析工具,与其他静态分析工具(如Checkstyle和PMD)不同,FindBugs不注重样式或者格式,它专注于寻找真正的缺陷或者潜在的性能问题,它可以帮助java工程师提高代码质量以及排除隐含的缺陷。有了静态分析工具,就可以在不实际运行程序的情况对软件进行分析。
最新版本是1.3.9.20090821,下载地址 http://findbugs.sourceforge.net/downloads.html
FindBugs运用Apache BCEL 库分析类文件(class文件)而不是源代码,将字节码与一组缺陷模式进行对比以发现可能的问题。FindBugs的检测器已增至300多条,被分为不同的类型,常见的类型如下:
- 正确性(Correctness):这种归类下的问题在某种情况下会导致bug,比如错误的强制类型转换等。
- 最佳实践反例(Bad practice):这种类别下的代码违反了公认的最佳实践标准,比如某个类实现了equals方法但未实现hashCode方法等。
- 多线程正确性(Multithreaded correctness):关注于同步和多线程问题。
- 性能(Performance):潜在的性能问题。
- 安全(Security):安全相关。
- 高危(Dodgy):FindBugs团队认为该类型下的问题代码导致bug的可能性很高。
2 在Eclipse中安装FindBugs插件
以下为我的安装步骤,可能大家用的是MyEclipse步骤不仅相同。
Step 1:
Step 2:
Step 3:
3 在Eclipse中使用FindBugs操作步骤
3.1 打开FindBugs视图

step2:
右键单击你要检测的工程、包或文件-->Find Bugs-->Find Bugs。

check完成后将在Bug Explorer视图中看到问题列表,该列表以问题类型组织。

展开列表,双击列表中具体的问题就可以定位的具体的代码行。

4 配置FindBugs
在这里可以对FindBugs规则等进行详细设置。选择你的项目,右键 --> Properties --> FindBugs -->

4.1 Run Automatically开关
当此项选中后,FindBugs将会在你修改Java类时自动运行,如你设置了Eclipse自动编译开关后,当你修改完Java文件保存,FindBugs就会运行,并将相应的信息实时显示。
当此项没有选中,你只能每次在需要的时候自己去运行FindBugs来检查你的代码。
4.2 Detector Configuration选择项
在这里你可以选择所要进行检查的相关的Bug Pattern条目,你可以根据需要选择或去掉相应的 检查条件。

4.3 Minimum priority to report选择项
这个选择项是让你选择哪个级别的信息进行显示,有Low、Medium、High三个选择项可以选择,很类似于Log4J的级别设置啦。 比如:
- High选择项:只有是High级别的提示信息才会被显示;
- Medium选择项:只有是Medium和High级别的提示信息才会被显示;
- Low选择项:所有级别的提示信息都会被显示。
4.4 Report bug categories选择项
在这里是一些显示Bug分类的选择:
- Malicious code vulnerability关于恶意破坏代码相关方面的
- Correctness关于代码正确性相关方面的
- Internationalization关于代码国际化相关方面的
- Performance关于代码性能相关方面的
- Multithreaded correctness关于代码多线程正确性相关方面的
5 Ant 使用简介
有了 Ant 这样的自动化机制,就可以以多种方法监视软件质量。有许多种扫描源代码和二进制文件的工具,但是其中最流行的两种是 PMD 和 FindBugs。PMD 扫描源代码文件,并根据一系列规则检查其中的代码。如果代码有问题,它就会报告一个违规。FindBugs 的作用与 PMD 相似,但是它扫描二进制文件(即类文件)并报告 bug。
以下为配置脚本:
<project name="analyze_asm_util" default="findbugs"> <!-- findbugs task definition -->
<property name="findbugs.home" value="/Users/ben/Documents/workspace/findbugs/findbugs" />
<property name="jvmargs" value="-server -Xss1m -Xmx800m -Duser.language=en -Duser.region=EN -Dfindbugs.home=${findbugs.home}" /> <path id="findbugs.lib">
<fileset dir="${findbugs.home}/lib">
<include name="findbugs-ant.jar"/>
</fileset>
</path> <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
<classpath refid="findbugs.lib" />
</taskdef> <taskdef name="computeBugHistory" classname="edu.umd.cs.findbugs.anttask.ComputeBugHistoryTask">
<classpath refid="findbugs.lib" />
</taskdef> <taskdef name="setBugDatabaseInfo" classname="edu.umd.cs.findbugs.anttask.SetBugDatabaseInfoTask">
<classpath refid="findbugs.lib" />
</taskdef> <taskdef name="mineBugHistory" classname="edu.umd.cs.findbugs.anttask.MineBugHistoryTask">
<classpath refid="findbugs.lib" />
</taskdef> <!-- findbugs task definition -->
<target name="findbugs">
<antcall target="analyze" />
<antcall target="mine" />
</target> <!-- analyze task -->
<target name="analyze">
<!-- run findbugs against asm-util -->
<findbugs home="${findbugs.home}"
output="xml:withMessages"
timeout="90000000"
reportLevel="experimental"
workHard="true"
effort="max"
adjustExperimental="true"
jvmargs="${jvmargs}"
failOnError="true"
outputFile="out.xml"
projectName="Findbugs"
debug="false">
<class location="asm-util-3.0.jar" />
</findbugs>
</target> <target name="mine"> <!-- Set info to the latest analysis -->
<setBugDatabaseInfo home="${findbugs.home}"
withMessages="true"
name="asm-util-3.0.jar"
input="out.xml"
output="out-rel.xml"/> <!-- Checking if history file already exists (out-hist.xml) -->
<condition property="mining.historyfile.available">
<available file="out-hist.xml"/>
</condition>
<condition property="mining.historyfile.notavailable">
<not>
<available file="out-hist.xml"/>
</not>
</condition> <!-- this target is executed if the history file do not exist (first run) -->
<antcall target="history-init">
<param name="data.file" value="out-rel.xml" />
<param name="hist.file" value="out-hist.xml" />
</antcall>
<!-- else this one is executed -->
<antcall target="history">
<param name="data.file" value="out-rel.xml" />
<param name="hist.file" value="out-hist.xml" />
<param name="hist.summary.file" value="out-hist.txt" />
</antcall>
</target> <!-- Initializing history file -->
<target name="history-init" if="mining.historyfile.notavailable">
<copy file="${data.file}" tofile="${hist.file}" />
</target> <!-- Computing bug history -->
<target name="history" if="mining.historyfile.available">
<!-- Merging ${data.file} into ${hist.file} -->
<computeBugHistory home="${findbugs.home}"
withMessages="true"
output="${hist.file}">
<dataFile name="${hist.file}"/>
<dataFile name="${data.file}"/>
</computeBugHistory> <!-- Compute history into ${hist.summary.file} -->
<mineBugHistory home="${findbugs.home}"
formatDates="true"
noTabs="true"
input="${hist.file}"
output="${hist.summary.file}"/>
</target> </project>
6 总结
更多详情,请查阅官方手册:
http://findbugs.sourceforge.net/manual/index.html
参考文献:
http://findbugs.sourceforge.net/manual/index.html
http://blog.csdn.net/strawbingo/article/details/5924005
http://www.ibm.com/developerworks/cn/education/java/j-cq11207/section6.html
白盒静态自动化测试工具:FindBugs使用指南的更多相关文章
- 白盒静态自动化测试工具:PMD使用指南
参考文献:http://www.oschina.net/p/pmd/http://www.cnblogs.com/flyme/archive/2011/09/09/2172548.htmlhttp:/ ...
- JAVA语言搭建白盒静态代码、黑盒网站插件式自动化安全审计平台
近期打算做一个插件化的白盒静态代码安全审计自动化平台和黑盒网站安全审计自动化平台.现在开源或半开源做黑盒网站安全扫描的平台,大多是基于python脚本,安全人员贡献python脚本插件增强平台功能.对 ...
- 移动測试技术保护源码!解码全球首款移动端白盒測试工具ThreadingTest (文章转自己主动点科技)
作者 智晓锋 - 2014/07/14 自从斯诺登曝光美监听丑闻事件之后,我国政府就将信息安全问题上升到了国家安全的高度.基于此.国内的一家创业公司推出了智能型Android真机白盒測试以及开发辅助类 ...
- python自动化测试工具selenium使用指南
概述 selenium是网页应用中最流行的自动化测试工具,可以用来做自动化测试或者浏览器爬虫等.官网地址为:https://www.selenium.dev/.相对于另外一款web自动化测试工具QTP ...
- GTest Google的一种白盒单元测试框架 开源项目
GTest为google开源的白盒单元测试跨平台测试框架,含丰富的断言.类型参数化测试.死亡测试.以及其他的测试选项设置.文件保存等,以下将对该项目C++的实现进行简要的分析,作为学习记录备份. 基本 ...
- 常用自动化测试工具介绍(支持B/S、C/S)
一.功能测试工具1.QTP测试工具 全名HP QuickTest Professional software ,最新的版本为HP QuickTest Professional 11.0 QTP是qui ...
- APP移动端自动化测试工具选型“兵器谱”一览(主流开源工具)
(下面大多数工具都是开源工具,在github,码云等开源平台都能找到) "测试那点事儿”在看到360旗下的测试团队整理的关于目前APP移动端自动化相关的工具,觉得总结的很到位,对目前大多数中 ...
- 商业级别Fortify白盒神器介绍与使用分析
转自:http://www.freebuf.com/sectool/95683.html 什么是fortify它又能干些什么? 答:fottify全名叫:Fortify SCA ,是HP的产品 ,是一 ...
- 阿里创新自动化测试工具平台--Doom
摘要: 阿里内部诞生一了个依赖真实流量用于自动回归的自动化测试平台,通过创新的自动mock机制不仅支持读接口的回归验证,同时支持了写接口验证,在内部产生了极大价值,有价值的东西就应该分享,目前该工具已 ...
随机推荐
- node实现缓存
内容: 1.缓存基本原理 2.node实现缓存 1.缓存基本原理 第一重要.缓存策略: cache-control:用于控制缓存,常见的取值有private.no-cache.max-age.must ...
- 在IDEA下使用Spring Boot的热加载(Hotswap)
你是否遇到过这样的困扰: 当你写完一段代码后,要看到效果,必须点击IDEA的停止按钮,然后再次重启启动项目,你是否觉得这样很烦呢? 如果你觉得很烦,本文就是用来解决你的问题的. 所谓热加载,就是让我们 ...
- 网络层-IP地址
以下内容是IPv4 IP地址长度32位,Java里面一个int的长度,总共分为5类IP地址 1:分类编址 A类IP地址0开头: A类有31个位置可以变化,总数是2^31个, [(0 ...
- 9. MyEclipse中的SVN操作手册
该文章转载出处:http://blog.sina.com.cn/s/blog_8a3d83320100zhmp.html 1.导入项目 点击工具栏上的[File-Import],进入下图 (如果你的 ...
- https Configure a Spring Boot app for HTTPS on Amazon AWS.
参考: https://geocolumbus.github.io/HTTPS-ELB-AWS-Spring-Boot/ 1. 在服务器端配置 证书 域名 映射 2. 导入依赖: <depe ...
- 数据库中查询json 样式的值的sql语句
参考:http://www.lnmp.cn/mysql-57-new-features-json.html 方式一: 可以查到json中的Key:value SELECT * FROM EDI.edi ...
- xml转json的方法
.第一种方法 使用JSON-JAVA提供的方法,之前一直使用json-lib提供的方法转json,后来发现了这个开源项目,觉得用起来很不错,并且可以修改XML.java中的parse方法满足自己的转换 ...
- 4.struts2的配置文件优先级
转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html 在struts2中一些配置(比如常量)可以同时在struts-default ...
- linux 安装svn服务器
一.下载 http://subversion.tigris.org/downloads/subversion-1.6.1.tar.gz http://subversion.tigris.org/dow ...
- nginx直接返回json
尝试配置nginx.conf之后,访问直接变成下载文件... 查阅之后,发现需要配置返回内容的格式. location ~ ^/get_json { default_type application/ ...