当前位置:网站首页>Understanding of software test logic coverage
Understanding of software test logic coverage
2022-06-29 19:37:00 【Dream not】
determine 、 Conditions 、 Use cases
for(int i=2;i<=n && k==1;i++){
if(m%i==0){
break;
}
}
The above code means when k = 1 k=1 k=1 when , find [ 2 , n ] [2,n] [2,n] Within the interval m m m The first factor of , Take this as an example
Judgment and condition
determine , Such as if、for、while And so on
Conditions ( Logical conditions ), And one Logical judgment statement It corresponds to a Basic conditions
A number of Basic conditions It can be done through 、 or 、 Unequal logical connectives form Compound condition
Be careful , The question is to meet the needs of coverage Logical conditions when , According to the meaning of the question, you can judge by yourself Basic conditions still Compound condition
As in the above code Logical judgment sub statement yes
i<=nandk==1andm%i==0If the above code is satisfied 100% Determine what is required for coverage Logical conditions yes
i<=n And k=1andi>n or k≠1andm%i=0andm%i≠0If the above code is satisfied 100% Required for conditional coverage Logical conditions yes
i<=nandi>nandk=1andk≠1andm%i=0andm%i≠0
in other words , Yes n n n individual Basic conditions , n n n individual Basic conditions constitute m m m individual Compound condition
- To meet the 100% Decision coverage rule most Yes 2 m 2m 2m Logical conditions
- To meet the 100% Conditional coverage is most Yes 2 n 2n 2n Logical conditions
The test case
The test case It refers to the specific value of a group of variables , One The test case It may be possible to satisfy multiple Logical conditions
What we need to see clearly is 100% Cover the required Logical conditions Or at least The test case , One The test case It may be possible to satisfy multiple Logical conditions
If the above code is satisfied 100% One set of test cases covered by the condition is
{n=2、m=3、k=1}: Satisfyi<=n And k=1andm%i=0andm%i≠0{n=0、m=3、k=1}: Satisfyi>n or k≠1
If the above code is satisfied 100% One set of test cases covered by the condition is
{n=2、m=3、k=1}: Satisfyi<=nandk=1andm%i=0andm%i≠0{n=0、m=3、k=0}: Satisfyi>nandk≠1
The number of required logical conditions is the same as Minimum test cases Quantity is not directly related to …… Because a test case may satisfy several logical conditions
Real example
void cal( int n ) {
int g, s, b, q;
if ( ( n > 1000 ) && ( n < 2000 ) ) {
g = n % 10;
s = n % 100 / 10;
b = n / 100 % 10;
q = n / 1000;
if( ( q + g ) == ( s + b ) ) {
printf("%-5d", n);
}
}
return;
}

Logical coverage
The logic coverage part of this article is simple , You can check this article for details
《 White box test case design method 》
https://blog.csdn.net/tianlin151/article/details/115665358
Logical coverage includes the following :
- Statement override (Statement Coverage, SC)
- Determine coverage (Decision Coverage, DC)
- Conditional coverage (Condition Coverage,CC)
- Judge whether the condition covers (Condition/ Decision Coverage, CDC)
- Conditional combination covering (Multiple Condition Coverage, MCC)
- Path coverage (Path Coverage, PC)
void f(double x, double y, double z){
double num1, num2;// Sentence block 1
if(x>=0 && y!=0){
num1=sqrt(x)/y;// Sentence block 2
printf("num1 is %f\n",num1);// Sentence block 2
}
else{
printf("num1 is invalid\n");// Sentence block 3
}
if(z>=0){
num2=z;// Sentence block 4
printf("num2 is %f\n",num2);// Sentence block 4
}
else{
num2=-z;// Sentence block 5
printf("num2 is %f\n",num2);// Sentence block 5
}
printf("end of calculation\n");// Sentence block 6
printf("goodbye\n");// Sentence block 6
}
The above code means to calculate in sequence x y \frac{\sqrt{x}}{y} yx and ∣ z ∣ |z| ∣z∣, The flow chart is as follows , The following text takes this as an example

if(x>=0 && y!=0)determine , Write it down as P1if(z>=0)determine , Write it down as P2x>=0Conditions , Write it down as C1y!=0Conditions , Write it down as C2z>=0Conditions , Write it down as C3
Statement override
Design test cases , Each statement in the program is executed at least once .
For the example above 100% Statement coverage requires statement blocks 1、 Sentence block 2、 Sentence block 3、 Sentence block 4、 Sentence block 5、 Sentence block 6 Are executed at least once
Determine coverage ( Branch coverage )
Design test cases , Make every judgment in the program ” really “ and ” false “ Are executed at least once . namely : Each branch in the program executes at least once .
For example 100% To determine the coverage is to P1、P2 Each is true and false at least once
Accessible 100% Determine the satisfaction of one set of test cases covered :
- The test case 1: At the same time satisfy P1 really 、P2 really
- The test case 2: At the same time satisfy P1 false 、P2 false
Conditional coverage
Design test cases , So that each condition in the decision takes the true value at least once , Once take a false value .
For example 100% Conditional coverage is the need to C1、C2、C3 Each is true and false at least once
Accessible 100% The satisfaction of one set of test cases covered by the condition :
- The test case 1: At the same time satisfy C1 really 、C2 really 、C3 really
- The test case 2: At the same time satisfy C1 false 、C2 false 、C3 false
determine - Conditional coverage
Design test cases , Make the judgment result of each judgment in the tested program ( True and false ) At least once , meanwhile , Possible values of each logical condition ( True and false ) And be satisfied at least once . That is to satisfy at the same time 100% Determine coverage and 100% Criteria for conditional coverage .
For example 100% determine - Conditional coverage is the need to P1、P2、C1、C2、C3 Each is true and false at least once
Accessible 100% determine - The satisfaction of one set of test cases covered by the condition :
- The test case 1: At the same time satisfy C1 really 、C2 really 、P1 really 、C3 really 、P2 really
- The test case 2: At the same time satisfy C1 false 、C2 false 、P1 false 、C3 false 、P2 false
Conditional combination covering
Design test cases , Make all possible combinations of condition results in each decision in the tested program execute at least once .
in other words , Yes n n n individual Basic conditions , Every Basic conditions There is a true and a false 2 In this case , When combined with each other, there will be 2 n 2^n 2n Test cases
Accessible 100% The satisfaction of one set of test cases covered by the condition combination :
- The test case 1:C1 really 、C2 really 、C3 really
- The test case 2:C1 really 、C2 really 、C3 false
- The test case 3:C1 really 、C2 false 、C3 really
- The test case 4:C1 really 、C2 false 、C3 false
- The test case 5:C1 false 、C2 really 、C3 really
- The test case 6:C1 false 、C2 really 、C3 false
- The test case 7:C1 false 、C2 false 、C3 really
- The test case 8:C1 false 、C2 false 、C3 false
Path coverage
Design test cases , Covering all possible paths in the program .
For example, the path is required a、b、c、d、e、f、g、h、i、j、k Walk at least once
边栏推荐
- Installation and configuration of MariaDB
- 以其他组件为代价的性能提升不是好提升
- Inception 新结构 | 究竟卷积与Transformer如何结合才是最优的?
- Violent solution to the question of guessing the ranking
- npm ERR! fatal: early EOF npm ERR! fatal: index-pack failed
- Win11策略服务被禁用怎么办?Win11策略服务被禁用的解决方法
- Win11系统小组件打不开?Win11系统小组件无法打开解决方法
- 3-3主機發現-四層發現
- 一个mysql里有3306端口下,一个mysql有20多个数据库,怎么一键备份20多个数据库,做系统备份,防止数据误删除?
- 福昕软件受邀亮相2022先进制造业数智发展论坛
猜你喜欢

逻辑结构与物理结构

【软件测试】01 -- 软件生命周期、软件开发模型

C#_摄像头图像转换为Bitmap格式及绘制十字线

The concept and properties of mba-day26 number

Win11系统频繁断网怎么办?Win11网络不稳定的解决方法

JVM(4) 字节码技术+运行期优化

Where is the win11 installation permission set? Win11 installation permission setting method

3-3主機發現-四層發現

The sales volume could not catch up with the speed of taking money. Weima went to Hong Kong for emergency rescue

How to install and use computer SSD hard disk
随机推荐
KDD 2022 | 協同過濾中考慮錶征對齊和均勻性
Arm 全面计算解决方案重新定义视觉体验强力赋能移动游戏
AI scene Storage Optimization: yunzhisheng supercomputing platform storage practice based on juicefs
The sales volume could not catch up with the speed of taking money. Weima went to Hong Kong for emergency rescue
With these four security testing tools, software security testing can be said so easy!
Test method learning
KDD 2022 | 协同过滤中考虑表征对齐和均匀性
【历史上的今天】6 月 29 日:SGI 和 MIPS 合并;微软收购 PowerPoint 开发商;新闻集团出售 Myspace
深度好文 | YOLOv5+DeepSORT多目标跟踪深入解读与测试(含源码)
【精品】pinia详解
One hour to build a sample scenario sound network to release lingfalcon Internet of things cloud platform
What if the win11 policy service is disabled? Solution to disabling win11 policy service
docker compose 部署Flask项目并构建redis服务
JVM(4) 字節碼技術+運行期優化
JVM(2) 垃圾回收
jfinal中如何使用过滤器监控Druid监听SQL执行?
Connaissance générale des paramètres de sécurité du serveur Cloud
洞见科技作为「唯一」隐私计算数商,「首批」入驻长三角数据要素流通服务平台
Shell bash script note: there must be no other irrelevant characters after the escape character \ at the end of a single line (multi line command)
jfinal中如何使用过滤器监控Druid监听SQL执行?