qacl7
TRANSCRIPT
-
8/2/2019 QACL7
1/15
White Box Testing
-
8/2/2019 QACL7
2/15
Branch Coverage
This metric has the advantage of simplicity without the problemsof statement coverage.
A disadvantage is that this metric ignores branches withinboolean expressions which occur due to short-circuit operators.
For example, consider the following C/C++/Java code fragment:if (condition1 && (condition2 || function1())) statement1; else
statement2;
This metric could consider the control structure completelyexercised without a call to function1.
The test expression is true when condition1 is true andcondition2 is true, and the test expression is false whencondition1 is false. In this instance, the short-circuit operatorspreclude a call to function1.
-
8/2/2019 QACL7
3/15
Condition Coverage
A branch predicate may have morethan one condition.
input(X,Y)
if(Y0) and (not EOF) do
input(X)Y := Y-1
end_while
-
8/2/2019 QACL7
4/15
Condition Coverage(contd)
Condition Coverage requires thateach condition will have been Trueat least once and False at leastonce.
What is the relationship betweenBranch and Condition Coverage?
-
8/2/2019 QACL7
5/15
Condition Coverage(contd)
ifA or B thens1
elses2
end_if_then_else
A B Branch
test 1 T F true
test 2 F F false
-
8/2/2019 QACL7
6/15
Condition Coverage(contd)
ifA or B thens1
elses2
end_if_then_else
A B Branch
test 3 T F true
test 4 F T true
-
8/2/2019 QACL7
7/15
condition coverage vs
decision coverage
Full condition coverage does not guarantee full decisioncoverage.
For example, consider the following C++/Java fragment.
bool f(bool e) { return false; }bool a[2] = { false, false };if (f(a && b)) ...if (a[int(a && b)]) ...if ((a && b) ? false : false) ...
All three of the if-statements above branch false regardless of thevalues of a and b. However if you exercise this code with a and bhaving all possible combinations of values, condition coveragereports full coverage.
-
8/2/2019 QACL7
8/15
Branch/ConditionCoverage
Branch/Condition Coveragerequires that both Branch ANDCondition Coverage will have beenachieved.
Therefore, Branch/Condition Coveragesubsumes both Branch Coverage and
Condition Coverage.
-
8/2/2019 QACL7
9/15
Compound ConditionCoverage
What if the compiler generates codethat masks the evaluation ofconditions?
That is, suppose
if (A) or (y/x=5) then...
is compiled in such a way that if A istrue, y/x=5 will not be evaluated.
-
8/2/2019 QACL7
10/15
Compound ConditionCoverage (contd)
Compound Condition Coveragerequires that all combinations ofcondition values at every branch
statement will have been covered,and that every entry point will havebeen taken, at least once.
Also know as Multiple Condition
Coverage. Subsumes Branch/Condition Coverage,
regardless of the order in which
conditions are evaluated.
-
8/2/2019 QACL7
11/15
Multiple Condition Coverage
Criterion:
Every atomic (i.e. does not include AND or OR)condition must be true and false at some point
during test execution.
In a compound logical statement (i.e. includesAND and OR), every combination of atomicconditions must be covered during test execution.
Achieving multiple condition coverage alsosatisfies statement and branch coverage
-
8/2/2019 QACL7
12/15
Compound ConditionCoverage
input(X,Y)
if(Y
-
8/2/2019 QACL7
13/15
Need cases where1. a > 1 is true andb = 0 is true
2. a > 1 is true andb = 0 is false
3. a > 1 is false andb = 0 is true
4. a > 1 is false andb = 0 is false
5. a = 2 is true and x > 1 is true
6. a = 2 is true and x > 1 is false
7. a = 2 is false and x > 1 is true
8. a = 2 is false and x > 1 is false
Multiple Condition Coverage
int proc(int a, int b, int x){if ( (a>1)&&(b==0) )
{
x = x/a;
}if ( (a==2)||(x>1) )
{
x = x+1;}
return x;
}
-
8/2/2019 QACL7
14/15
Multiple Condition Coverage
Possible input:
a = 2, b = 0, x = 2
[1][5]
a = 2, b = 1, x = 0
[2][6]
a = 0, b = 0, x = 2
[3][7]
a = 0, b = 1, x = 0
[4][8]
1. a > 1 is true andb = 0 is true
2. a > 1 is true andb = 0 is false
3. a > 1 is false andb = 0 is true
4. a > 1 is false andb = 0 is false
5. a = 2 is true and x > 1 is true
6. a = 2 is true and x > 1 is false
7. a = 2 is false and x > 1 is true
8. a = 2 is false and x > 1 is false
-
8/2/2019 QACL7
15/15
Multiple Condition Coverage
Multiple condition coveragecovers all branches andstatements.
Input values:
a = 2, b = 0, x = 2a = 2, b = 1, x = 0
a = 0, b = 0, x = 2
a = 0, b = 1, x = 0
Paths covered
1
3
4
5
71 2 4 5 7
1 2 4 6 7
1 2 4 6 7
a > 1 ANDb = 0
a == 2
OR x>1
xx/a
x x+1
false
true
true
false
1
2
5
3
7
4
6