技术分享 | 静态扫描体系集成
本文节选自霍格沃兹测试开发学社内部教材
FindBugs 是一个 Java 项目的静态代码扫描工具,它支持的项目类型包括 Maven,Grade,Ant 等,可以在不运行程序的前提下对软件进行潜在 Bug 的分析,帮助团队在程序运行之前就最大程度发现隐藏较深的问题,提示的内容包含真正的权限和潜在可能发生的错误问题;可以把它与持续集成工具 Jenkins 进行集成,这样就能在代码提交后自动对提交的代码进行静态扫描,找出潜在的代码问题。
环境准备
Jenkins 服务
运行 FindBugs 单元测试的节点机器
部署 Java + Maven
Jenkins 上已安装了 Warnings Next Generation 插件
FindBugs 单元测试项目:
https://gitee.com/ceshiren/iWeb.git
项目的配置
在 Maven 项目的配置 pom.xml 文件中需要把 findbugs-maven-plugin 工具配置上。

在 jenkins 中建立一个自由风格的项目。

配置好运行的节点机器,此机器是环境准备中的节点机器。

配置代码源,将被测项目代码的 git 地址配置到此处。

在构建(Build)中点击增加构建步骤(Add build step),构建步骤中选择执行 shell(Execute shell)。

在构建后步骤(Post-build Actions),选择 Record compiler warnings and static analysis results。

在静态工具中选择 FindBugs 在 Report File Pattern 配置上
**/findbugsXml.xml
。

执行 job
点击执行后,job 将会拉取代码进行静态扫描操作,执行完成之后在 job 的首页左下部分有一个 FindBugs Warnings 的按钮。

点击此按钮后能展示出来 FindBugs 找到的问题信息。

点击每一条问题信息左边的加号都能进入到具体哪行代码报出了问题,出问题的具体信息,就能根据提示的信息去分析可能的出错,与开发人员进行沟通解决;多次构建操作后就能看到趋势图的展示。

更多学习资料戳下方!!!
评论