Condition coverage testing is a type of white-box testing that tests all the conditional expressions in a program for all possible outcomes of the conditions. It is also called predicate coverage.
Note: Condition coverage testing tests the conditions independently of each other.
In branch coverage, all conditions must be executed at least once. On the other hand, in condition coverage, all possible outcomes of all conditions must be tested at least once.
For example, consider the code snippet below:
int a = 10;if (a > 0){cout<<"a is positive";}
a > 0
is executed at least once.a > 0 = True
and a > 0 = False
of the condition a > 0
are executed at least once.Consider the code snippet below, which will be used to conduct condition coverage testing:
int num1 = 0;if(num1>0){cout<<"valid input";}else{cout<<"invalid input";}
The condition coverage testing of the code above will be as follows:
Test case number | num1>0 | Final output |
1 | True | True |
2 | False | False |
Consider the code snippet below, which will be used to conduct condition coverage testing:
int num1 = 0;int num2 = 0;if((num1>0 || num2<10)){cout<<"valid input";}else{cout<<"invalid input";}
The condition coverage testing of the code above will be as follows:
Test case number | num1>0 | num2<10 | Final output |
1 | True | Not required | True |
2 | False | True | True |
3 | False | False | False |
Consider the code snippet below, which will be used to conduct condition coverage testing:
int num1 = 0;int num2 = 0;if((num1>0) && (num1+num2<15)){cout<<"valid input";}else{cout<<"invalid input";}
The condition coverage testing of the code above will be as follows:
Test case number | num1>0 | num1+num2<15 | Final output |
1 | True | True | True |
2 | True | False | False |
3 | False | Not required | False |
Consider the code snippet below, which will be used to conduct condition coverage testing:
int num1 = 0;int num2 = 0;if((num1>0 || num2<10) && (num1+num2<15)){cout<<"valid input";}else{cout<<"invalid input";}
The condition coverage testing of the code above will be as follows:
Test case number | num1>0 | num2<10 | num1+num2<15 | Final output |
1 | True | don't care | True | True |
2 | True | don't care | False | False |
3 | False | True | True | True |
4 | False | True | False | False |
5 | False | False | Not required | False |
Free Resources