文档详情

Cobertura测试代码覆盖率.ppt

发布:2017-05-08约1.17万字共35页下载文档
文本预览下载声明
Command line方式: Ser文件合并: Cobertura支持将不同测试环境的cobertura.ser统计文件进行合并。如:同一版本的项目在不同的环境下(或集群环境中)进行测试后,代码覆盖率需要合并报告。合并cobertura.ser统计文件就能够满足该要求: cobertura-merge.bat --datafile D:\cobertura\datafile\cobertura.ser D:\cobertura\uat03\cobertura.ser D:\cobertura\uat04\cobertura.ser 总结 覆盖率数据只能代表你测试过哪些代码,不能代表你是否测试好这些代码 不要一味的追求数据,为了提高代码测试覆盖率而去设计测试案例; There Two One 要以代码测试覆盖率为参考,让它来帮助我们设计更加有意义,高效的测试用例; ? ? ? 问题探讨 例如: int?foo(int?a,?int?b) { ????int?nReturn?=?0; ????if?(a??10) ????{//?分支一 ????????nReturn?+= 1; ????} ????if?(b??10) ????{//?分支二 ????????nReturn?+= 10; ????} ????return?nReturn; } 语句覆盖(覆盖率100%) TestCase?a?=?5,?b?=?5?? nReturn = 11 b. 判定覆盖(覆盖率100%) TestCase1 a?=?5,?? b?=?5???? nReturn = 11 TestCase2 a?=?15,?b?=?15?? nReturn = 0 c. 条件覆盖(覆盖率100%) TestCase1 a?=?5,?? b?=?15?? nReturn = 1 TestCase2 a?=?15,?b?=?5?? ? nReturn = 10 d. 路径覆盖(覆盖率100%) TestCase1 a?=?5,? ? b?=?5???? nReturn = 0 TestCase2 a?=?15,? b?=?5???? nReturn = 1 TestCase3 a?=?5,??? b?=?15?? nReturn = 10 TestCase4 a?=?15,? b?=?15?? nReturn = 11 McCabe方法包括若干项度量指标。常用的有如下几项: (1)圈复杂度:圈复杂度是用来衡量一个模块判定结构的复杂程度。在程序控制流程图中,节点是程序中代码的最小单元,边代表节点间的程序流。一个有e条边和n个节点的流程图F,其圈复杂度为:VF =e-n+2。圈复杂度越高,程序中的控制路径越复杂。McCabe指出,典型的程序模块的圈复杂度为10。 (2)基本复杂度:基本复杂度是用来衡量程序结构化程度的。如果流程图G中的结构化子图的数量是m,则其基本复杂度为:EVF =V ? F -m。当基本复杂度为1,这个模块是充分结构化的;当基本复杂度大于1而小于循环复杂度,这个模块是部分结构化的;当基本复杂度等于循环复杂度时,这个模块是完全非结构化的。 (3)模块复杂度:模块设计复杂度用来衡量模块判定结构,即衡量模块与模块的调用关系。从模块流程图中移取那些不包含调用子模块的判定和循环结构时求得的循环复杂度就是模块设计复杂度。 Line Coverage: The percent of lines executed by this test run. Branch Coverage: The percent of branches executed by this test run. Complexity: Average McCabes cyclomatic code complexity for all methods. This is basically a count of the number of different code paths in a method (incremented by 1 for each if statement, while loop, etc.) N/A: Line coverage and branch coverage will appear as Not Applicable when Cobertura can not find line number information in the .class file. This happens for stub and skeleton classes, interfaces, or when the c
显示全部
相似文档