我们会看到又多了一个关于junit测试的.db文件!现在,我们已经使用clover统计完了覆盖率信息,之后创建clover报告,以直观方式来查看具体的覆盖率结果!这个任务需要在build.xml里创建任务。Clover的报告有多种方式:html、pdf、xml以及swingview的图形化报告,当然与eclipse等java的IDE集成,也会在IDE里创建报告;这里我们只演示html类型的报告!我们修改build.xml文件,添加如下任务:
这里的元素指产生的报告类型是当前的测试报告,还有历史报告,我们在后边讲解!这个报告是html格式,创建后的报告放在一个叫做clover_html的文件夹里,报告标题叫做Clover demo。
我们现在给出完整的修改后的build.xml文件:
moneytest build file
fork="yes">
fork="yes">
现在我们执行report这个任务:
C:cloversincky>ant report
Buildfile: build.xml
clover:
[clover-setup] Clover Version 1.3.8, built on May 18 2005
[clover-setup] loaded from: C:cloverlibclover.jar
[clover-setup] 30 day Evaluation License registered to sinckyzhang@163.com
[clover-setup] You have 10 day(s) before your Evaluation License expires.
[clover-setup] Clover is enabled with initstring 'C:cloversinckydemo_coverage.db'
report:
[clover-report] Clover Version 1.3.8, built on May 18 2005
[clover-report] loaded from: C:cloverlibclover.jar
[clover-report] 30 day Evaluation License registered to sinckyzhang@163.com
[clover-report] You have 10 day(s) before your Evaluation License expires.
[clover-report] Loaded results from 1 coverage recording.
[clover-report] Writing report to 'C:cloversinckyclover_html'
[clover-report] Done. Processed 1 packages.
BUILD SUCCESSFUL
Total time: 1 second
Buildfile: build.xml
clover:
[clover-setup] Clover Version 1.3.8, built on May 18 2005
[clover-setup] loaded from: C:cloverlibclover.jar
[clover-setup] 30 day Evaluation License registered to sinckyzhang@163.com
[clover-setup] You have 10 day(s) before your Evaluation License expires.
[clover-setup] Clover is enabled with initstring 'C:cloversinckydemo_coverage.db'
report:
[clover-report] Clover Version 1.3.8, built on May 18 2005
[clover-report] loaded from: C:cloverlibclover.jar
[clover-report] 30 day Evaluation License registered to sinckyzhang@163.com
[clover-report] You have 10 day(s) before your Evaluation License expires.
[clover-report] Loaded results from 1 coverage recording.
[clover-report] Writing report to 'C:cloversinckyclover_html'
[clover-report] Done. Processed 1 packages.
BUILD SUCCESSFUL
Total time: 1 second
现在你可以打开sincky下的clover_html文件夹下的index.html文件,如下所示:
报告最左边是包名,以及包下边的类;右边是主窗口,显示当前这个Money类的测试覆盖率,我们可以通过行号来查看到15、16、17行执行了156次,下边还会有两行一次也没有执行过,所以造成这个类整体的测试覆盖率不是100%。