白盒测试用例设计方法
白盒设计方法
静态:桌面检查、代码审查、代码走查、代码扫描工具
动态:
逻辑覆盖法:语句覆盖、判断覆盖、条件覆盖、判定条件覆盖、条件组合覆盖、路径覆盖
基本路径测试法
逻辑覆盖法:是通过对程序逻辑结构的遍历实现程序的覆盖
覆盖率:是用来度量测试完整性的一个手段
![](https://img-blog.csdnimg.cn/img_convert/66b90d80407652dc9c40c58af842beba.png)
![](https://img-blog.csdnimg.cn/img_convert/aeb071d5a07996a4ffb98c0c86c9e559.png)
语句覆盖:设计测试用例,使得程序中每条语句至少被执行一次
![](https://img-blog.csdnimg.cn/img_convert/631509439c8711a05d3c4d6ae016d813.png)
例如:
![](https://img-blog.csdnimg.cn/img_convert/da5963f070f5a25c807cd809c1711ebe.png)
![](https://img-blog.csdnimg.cn/img_convert/d3fa82cf9afc9d6ffbadf46002049184.png)
在六种逻辑覆盖标准中,语句覆盖标准最弱。不能准确的判断运算中的逻辑关系错误
![](https://img-blog.csdnimg.cn/img_convert/b5b4a06df7dec6d53cf22facf7d9ecde.png)
判定覆盖:也叫分支覆盖,设计测试用例,使得程序中的每个判断的“真”或“假”都至少被执行一次,即程序中的每个分支至少执行一次
![](https://img-blog.csdnimg.cn/img_convert/450d82085fdaae80096e586ed7076dd3.png)
例如:
![](https://img-blog.csdnimg.cn/img_convert/d8172e2b93fa91830727d04abc2c2b7b.png)
![](https://img-blog.csdnimg.cn/img_convert/7aae4b0fa6863aec93b31c0cf780e623.png)
只要满足了判定覆盖标准就一定满足语句覆盖标准,判定覆盖会忽略条件中取或(or)的情况
![](https://img-blog.csdnimg.cn/img_convert/7ee57fc257593a4702eed22375ae9d3e.png)
条件覆盖:设计测试用例,使得判定中的每个条件至少有一次取真值,有一次取假值
![](https://img-blog.csdnimg.cn/img_convert/a4d6fd1f584b95d1bb84e49d9ea3ff21.png)
例如:
![](https://img-blog.csdnimg.cn/img_convert/b3eb1e1fe1a3929bef52cd2877c4ea3b.png)
![](https://img-blog.csdnimg.cn/img_convert/9076a9780398de19ef471daba6cf3eec.png)
条件覆盖比判定覆盖,增加了对判定中所有条件的测试,但条件覆盖并不能保证判定覆盖
![](https://img-blog.csdnimg.cn/img_convert/e007bf9fde3277135a1d26b342dc08bf.png)
判定条件覆盖:设计测试用例,使得被测试程序中的每个判断本身的判定结果(真假)至少满足一次,同时,每个逻辑条件的可能值(真假)也至少被满足一次,即同时满足100%判定覆盖和100%条件覆盖的标准
![](https://img-blog.csdnimg.cn/img_convert/e8da8d34c9558d5a0504397d16617e42.png)
例如:
![](https://img-blog.csdnimg.cn/img_convert/517470bb5f076b1b82024eda7cc77a53.png)
![](https://img-blog.csdnimg.cn/img_convert/a79b04c2a4a925fc3d617c64cfa8ec71.png)
满足判定-条件覆盖标准一定能满足条件覆盖、判定覆盖和语句覆盖,判定条件覆盖会忽略条件中取或(or)的情况
![](https://img-blog.csdnimg.cn/img_convert/c17f32b7990aa4979df8d391b0ef6c01.png)
条件组合覆盖:设计测试用例,使得被测试程序中的每个判定中条件结果的所有可能组合至少被执行一次
![](https://img-blog.csdnimg.cn/img_convert/83f3a99825b506b3e71b6534acc2d8e7.png)
例如:
![](https://img-blog.csdnimg.cn/img_convert/0cdb1552ed5e276534ee677c86f75e7f.png)
![](https://img-blog.csdnimg.cn/img_convert/e06e99363cb9299bc40946e83204f386.png)
条件组合覆盖能满足判定覆盖、条件覆盖、判定-条件覆盖,也就包括语句覆盖,条件组合覆盖不能保证所有路径被执行
![](https://img-blog.csdnimg.cn/img_convert/3aaeb28be6f9128c27b9f4a598c43d23.png)
路径覆盖:设计测试用例,覆盖程序中所有可能的路径
![](https://img-blog.csdnimg.cn/img_convert/a511e7d4e0b213d75eec9e2ec50c75fa.png)
例如:
![](https://img-blog.csdnimg.cn/img_convert/986b048326efa5c07e337b6f0405cd8a.png)
![](https://img-blog.csdnimg.cn/img_convert/c3778c39d294db2319d045420a3333df.png)
路径覆盖可以对程序进行彻底的测试,比前面五种覆盖面都广,但是满足路径覆盖,并不一定能满足条件覆盖,也就不能满足条件组合覆盖
基本路径测试法:在程序控制流图的基础上,通过分析程序的环复杂性,导出可执行路径集合,从而设计测试用例
![](https://img-blog.csdnimg.cn/img_convert/3d2c6c3dfccf52172ebd739996572c53.png)
![](https://img-blog.csdnimg.cn/img_convert/f12a69d77ccf1c4a005a2afd740cd6d2.png)
![](https://img-blog.csdnimg.cn/img_convert/0be2bc1952f29ccdf279d6a396ed8c01.png)
![](https://img-blog.csdnimg.cn/img_convert/e5a9af2579bb1abdfba342f968b72e1f.png)
![](https://img-blog.csdnimg.cn/img_convert/213500ee887f9e6798ba2afd9805a514.png)
![](https://img-blog.csdnimg.cn/img_convert/6bf4a51c8979882ae67d74cba573f6f0.png)
总结:
主要应用于单元测试阶段
先静态,后动态
设计用例一般使用基本路径测试,重点模块使用多种覆盖率标准