此篇文章将阐述如何做到将多个Junit报告文件合并成一个汇总的报告文件,及如何FindBugs的的多个报告文件合并成一个汇总文件。
合并成一个汇总文件是非常必要的。因为一个项目会产生很多junit报告和findbugs报告,不利于作最终的统计且不是视觉和结构良好的文档。
<target name="report" depends="buid-all" description="Create Html File Of Report that only the property of junit not set or true">
<if>
<or>
<not>
<isset property="switch-junit"/>
</not>
<and>
<isset property="switch-junit"/>
<equals arg1="${switch-junit}" arg2="true"/>
</and>
</or>
<then>
<junitreport id="myJUnitReport" taskname="reported" todir="${report.dir}/junit" description="Junit Report">
<fileset dir="${report.dir}/junit">
<include name="TEST-*.xml"/>
</fileset>
<report format="noframes" todir="${report.dir}/html"/>
</junitreport>
</then>
</if>
<unionbugs to="${report.dir}/findbugs/findbugs.xml">
<fileset dir="${report.dir}/findbugs">
<include name="*_findbugsparts.xml"/>
</fileset>
</unionbugs>
<convertXmlToText home="${findbugs.home}" longBugCodes="true" input="${report.dir}/findbugs/findbugs.xml"
output="${report.dir}/html/findbugs_result.html" format="html"/>
</target>
关于 junitreport做如下几点说明,由于ant核心类库中提供了两个xsl文件分别为junit-frames.xsl、junit-noframes.xsl两个格式化文件所以,当format为noframes时其实就是对应的是junit-noframes.xsl文件,而为frames就是对应junit-frames.xsl文件。这两个文件定义在ant-junit.jar\org\apache\tools\ant\taskdefs\optional\junit\xsl 目录中 ,这两个xsl文件非常经典完全可以作为其他的输出文件的样式表。此构建工程中的buid结果就是采用junit-noframes.xsl作为样式表的。当你不想用此样式表时可以自己编写样式表文件此时用styledir属性来标志。
关于unionbugs使用做如下说明此任务是ant的扩展任务需要单独下载 http://findbugs.sourceforge.net
官方文档中做了详细的使用说明。
在这里摘抄一部分阐述一下unionBugs和computeBugHistory,这两个任务均能进行多个文件的合并。但有些区别
下面是官方的说明
If you have, for example, separately analyzing each jar file used in an application, you can use this command to combine the separately generated xml bug warning files into a single file containing all of the warnings.
Do not use this command to combine results from analyzing different versions of the same file; use computeBugHistory instead.
Specify the xml files on the command line. The result is sent to standard output
这句话中明确说明了这两个任务的区别也就是unionBugs用来合并同一个构建任务产生的多个fingbugs文件到一个单独的文件,而computeBugHistory用来合并同一个jar不同版本的findbugs文件。
根据语义我们采用unionbugs进行多个文件合并。
在uninonbugs的合并中有些地方需要注意后续文章中继续阐述