White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means...

47
White Box Testing Zahra Ali Background Information Statement Coverage Criterion Simple Example Statement Coverage: RecordProcessor.java Edge Coverage Criterion Simple Example Edge Coverage: RecordProcessor.java Condition Coverage Criterion Simple Example Path Coverage Criterion Simple Example Summary 1/34 White Box Testing SE 3S03 Zahra Ali Department of Computing and Software McMaster University Week of Feb 22, 2016

Transcript of White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means...

Page 1: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

1/34

White Box TestingSE 3S03

Zahra Ali

Department of Computing and SoftwareMcMaster University

Week of Feb 22, 2016

Page 2: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

2/34

Outline

Background Information

Statement Coverage CriterionSimple ExampleStatement Coverage: RecordProcessor.java

Edge Coverage CriterionSimple ExampleEdge Coverage: RecordProcessor.java

Condition Coverage CriterionSimple Example

Path Coverage CriterionSimple Example

Summary

Page 3: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

3/34

Background Information

I Recall that White Box Testing means using theinformation about the internal structure of the softwareto determine test cases.

I It may also be called unit structural testing

Page 4: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

4/34

Statement Coverage Criterion

I a test set T such that, by executing P for each d in T,each elementary statement of P is executed at leastonce.

I P behaves as a functionI d is an element in the domain D of PI elementary statements are usually assignment

statements, I/O statements and procedure calls

I Generally means execute every line of source code atleast once

Can you think of any weakness in just fulfilling this criterion?

I It fails to measure if statements with a false decisionoutcome.

Page 5: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

4/34

Statement Coverage Criterion

I a test set T such that, by executing P for each d in T,each elementary statement of P is executed at leastonce.

I P behaves as a functionI d is an element in the domain D of PI elementary statements are usually assignment

statements, I/O statements and procedure calls

I Generally means execute every line of source code atleast once

Can you think of any weakness in just fulfilling this criterion?

I It fails to measure if statements with a false decisionoutcome.

Page 6: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

5/34

Statement Coverage Criterion

Simple example:if (x < 6) {

x += 1;}

I How many test cases do we need to make all lines ofcode execute?

I Only 1 case, for example: <x = 4>

I Note that the case where x ≥ 6 does not get checkedusing this criterion.

Page 7: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

5/34

Statement Coverage Criterion

Simple example:if (x < 6) {

x += 1;}

I How many test cases do we need to make all lines ofcode execute?

I Only 1 case, for example: <x = 4>

I Note that the case where x ≥ 6 does not get checkedusing this criterion.

Page 8: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

5/34

Statement Coverage Criterion

Simple example:if (x < 6) {

x += 1;}

I How many test cases do we need to make all lines ofcode execute?

I Only 1 case, for example: <x = 4>

I Note that the case where x ≥ 6 does not get checkedusing this criterion.

Page 9: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

6/34

Statement Coverage Criterion

Consider the following change to the example:while (x < 6) {

x += 1;}

I Using the same value of x = 4, does this code have thefalse condition left unchecked?

No! The false condition executing is the only way thewhile loop will terminate.

Page 10: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

6/34

Statement Coverage Criterion

Consider the following change to the example:while (x < 6) {

x += 1;}

I Using the same value of x = 4, does this code have thefalse condition left unchecked?

No! The false condition executing is the only way thewhile loop will terminate.

Page 11: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

7/34

Statement Coverage Criterion

Example:

If we look at the function, we know that the highlightedconditional statements determine whether or not the bodycode is executed.

Page 12: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

8/34

Statement Coverage Criterion

I Our goal is to ensure every line of code is executed, sowe simply have to create test cases that satisfy thedifferent conditions.

I However, remember we want to try and keep our testset minimal for this testing technique. So, wherever wesee nested conditional statements, we just need to haveone test that satisfies all to meet the criterion.

Page 13: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

9/34

Statement Coverage Criterion

I So we begin by defining a test with inputsinputValid = false && count = 0

I For the exception to run, we need the inputValid = false(to enter the while loop) and count ≥ 4 so let’s pickinputValid = false && count = 4

So to complete statement coverage testing on the above, weonly need 2 test cases.

Page 14: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

10/34

Statement Coverage Criterion

Continuing on to the process() function, we follow the sameprocedure:

I A test to enter the conditional loop and test the bodycode needs lineNum ≤ RecordReader.MAX LINE NUMand endReached = false so let’s picklineNum = 8, RecordReader.MAX LINE NUM =50 and endReached = false

Page 15: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

11/34

Statement Coverage Criterion

I To satisfy these three for loops and the if statement,lineNum > 0, fieldChars.length > 0, chars.length > 1,and have at least one occcurence of fieldChars[j] ==chars[k]. Keeping in mind we want to keep test casesminimal, let’s picklineNum = 8, fieldChars = {’A’,’D’,’W’}, chars ={’A’,’D’,’W’},

Page 16: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

12/34

Statement Coverage Criterion

I With our previous test using lineNum = 8, we are sureto enter the while loop and the for loop to print the firsthalf of the line. In addition, the same test will allow usto enter the second half of the line when i = 1 andexecute the for block since chars.length would equal 3.

Page 17: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

13/34

Statement Coverage Criterion

I The code defaults the condition(i + SUBSECTION LENGTH ≥ lineNum) to thiselse-block, and we currently do not have a set of inputsto test this. To enter the while-block, lineNum must beat least 2. Since (1 + 6 ≥ 2) let’s picklineNum = 2

Page 18: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

14/34

Statement Coverage Criterion

I An example to satisfy these conditions could include,i = 5 and chars.length = 3. In context of testing, weneed a test case to have at least 5 lines, and we do -with lineNum = 8 and chars as previously defined.

Page 19: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

15/34

Statement Coverage Criterion

I Here we need an i such that ((i+1) % (2*6) != 6), sowe can choose i = 1 for that case. Our test conditionwith lineNum = 8 will execute this code.

Page 20: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

16/34

Statement Coverage Criterion

As a quick overview of what we just defined,

I Looking at each test case and bearing in mind theinitial conditions, we can minimize the tests:

Page 21: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

17/34

Statement Coverage Criterion

I If we look at the conditions we need for each case, wecan see that some tests must be executed together. Sowe continue to minimize...

I Leaving us with a final count of 3 test cases to invokeall the statements within the code:

Page 22: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

18/34

Edge Coverage Criterion

Recall the edge coverage criterion from class:I a test set T such that, by executing P for each d in T,

each edge of P’s control flow graph is traversed at leastonce.

I P is a program fragmentI d is an element in the domain D of P

Can you think of any weakness in just fulfilling this criterion?

I Compound boolean expressions (c1 ∨ c2) used inbranching clauses can end up having uncheckedconstituents that may cause errors later on.

Page 23: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

18/34

Edge Coverage Criterion

Recall the edge coverage criterion from class:I a test set T such that, by executing P for each d in T,

each edge of P’s control flow graph is traversed at leastonce.

I P is a program fragmentI d is an element in the domain D of P

Can you think of any weakness in just fulfilling this criterion?

I Compound boolean expressions (c1 ∨ c2) used inbranching clauses can end up having uncheckedconstituents that may cause errors later on.

Page 24: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

19/34

Edge Coverage Criterion

Simple example:if (x > 3 ∨ y = true) {

x += 1;}

I How many test cases do we need to make sure theif-block is executed, and also that it is skipped?

I 2 cases: one where the if-condition is met, and anotherwhere it is not. for example:< x = 4, y = true>, <x = 4, y = false>

I Note that 2 cases are not covered: one where x ≤ 3 andy = false, and another where x ≤ 3 and y = false.

Page 25: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

19/34

Edge Coverage Criterion

Simple example:if (x > 3 ∨ y = true) {

x += 1;}

I How many test cases do we need to make sure theif-block is executed, and also that it is skipped?

I 2 cases: one where the if-condition is met, and anotherwhere it is not. for example:< x = 4, y = true>, <x = 4, y = false>

I Note that 2 cases are not covered: one where x ≤ 3 andy = false, and another where x ≤ 3 and y = false.

Page 26: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

19/34

Edge Coverage Criterion

Simple example:if (x > 3 ∨ y = true) {

x += 1;}

I How many test cases do we need to make sure theif-block is executed, and also that it is skipped?

I 2 cases: one where the if-condition is met, and anotherwhere it is not. for example:< x = 4, y = true>, <x = 4, y = false>

I Note that 2 cases are not covered: one where x ≤ 3 andy = false, and another where x ≤ 3 and y = false.

Page 27: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

20/34

Edge Coverage Criterion

Back to our example

I Our statement coverage has executed all edges of thecontrol flow graph that have a line of code explicitlywritten.

I To ensure edge coverage, we need to go back throughthe program, and analyze which conditional statementswe do not satisfy so we can make sure our tests alsotake the path where they skip the conditional block ofcode.

Page 28: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

21/34

Edge Coverage Criterion

I Looking at the main function again, we have:

I Our while loop is always guaranteed to execute the pathwhere the condition is not met- that’s how itterminates. Our only worry is the if-statement blockhere, in which both outcomes have been coveredalready by our test cases.

Page 29: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

22/34

Edge Coverage Criterion

I Let’s consider our process function again:

I Again, this is a while loop, so we’re fine.

Page 30: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

23/34

Edge Coverage Criterion

I Process function consideration cont’d:

I Our only change we must make is ensure we have a testcase in which the character in the third field is not oneof the characters we’re looking for. Instead of making anew test case, let’s just alter the ones we have.

Page 31: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

24/34

Edge Coverage Criterion

I Our modified test cases now include the case where theif-condition is not met:

Page 32: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

25/34

Edge Coverage Criterion

I Our only concern is making sure a test case doesn’tmeet the condition- (i + SUBSECTION LENGTH <lineNum)...

Page 33: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

26/34

Edge Coverage Criterion

I ... which we already covered to meet the else condition:

Page 34: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

27/34

Edge Coverage Criterion

I The same goes for the next if-else condition, since weneeded to execute both blocks of code to meet thestatement coverage criterion.

I The if (k < chars.length - 1) block does not execute atthe end of each printed line, which covers the casewhen printing “ **** ” is skipped.

Page 35: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

28/34

Edge Coverage Criterion

I Which brings us to the end of our edge coverageconsideration, and we finish with the following testcases:

Page 36: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

29/34

Condition Coverage Criterion

Recall the condition coverage criterion from class:

I a test set T such that, by executing P for each elementin T, each edge of P’s control flow graph is traversed,and all possible values of the constituents of compoundconditions are exercised at least once.

I Notice that this criterion strengthens the edge coveragecriterion.

Can you think of any weakness in just fulfilling this criterion?

I We may traverse through all edges of the flow graphand possible constituent values, but this does notprotect us from errors like division by 0.

Page 37: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

29/34

Condition Coverage Criterion

Recall the condition coverage criterion from class:

I a test set T such that, by executing P for each elementin T, each edge of P’s control flow graph is traversed,and all possible values of the constituents of compoundconditions are exercised at least once.

I Notice that this criterion strengthens the edge coveragecriterion.

Can you think of any weakness in just fulfilling this criterion?

I We may traverse through all edges of the flow graphand possible constituent values, but this does notprotect us from errors like division by 0.

Page 38: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

30/34

Condition Coverage Criterion

Simple example:if (x % 2 = 0 ∨ y % 2 = 0) {

z = x/y;}

I How many test cases do we need to cover the conditioncoverage criterion?

I 4 cases: test each constituent in the compound booleanexpression <x is even, y is even>,<x is odd, y iseven>,<x is even, y is odd>,<x is odd, y is odd>:for example: < x = 4, y = 6>, <x = 5, y = 6> < x =4, y = 5>, <x = 5, y = 5>

I Note that even covering every case here does notprotect us from cases like division by 0.

Page 39: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

30/34

Condition Coverage Criterion

Simple example:if (x % 2 = 0 ∨ y % 2 = 0) {

z = x/y;}

I How many test cases do we need to cover the conditioncoverage criterion?

I 4 cases: test each constituent in the compound booleanexpression <x is even, y is even>,<x is odd, y iseven>,<x is even, y is odd>,<x is odd, y is odd>:for example: < x = 4, y = 6>, <x = 5, y = 6> < x =4, y = 5>, <x = 5, y = 5>

I Note that even covering every case here does notprotect us from cases like division by 0.

Page 40: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

30/34

Condition Coverage Criterion

Simple example:if (x % 2 = 0 ∨ y % 2 = 0) {

z = x/y;}

I How many test cases do we need to cover the conditioncoverage criterion?

I 4 cases: test each constituent in the compound booleanexpression <x is even, y is even>,<x is odd, y iseven>,<x is even, y is odd>,<x is odd, y is odd>:for example: < x = 4, y = 6>, <x = 5, y = 6> < x =4, y = 5>, <x = 5, y = 5>

I Note that even covering every case here does notprotect us from cases like division by 0.

Page 41: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

31/34

Path Coverage Criterion

Recall the path coverage criterion from class:

I a test set T such that, by executing P for each d in T,all paths leading from the initial to the final node of P’scontrol flow graph are traversed.

I Note that path coverage criterion → edge coveragecriterion.

Can you think of any weakness in just fulfilling this criterion?

I Generally, this criterion is impractical as in the generalcase the number of execution paths is very large. Thismakes traversing through all control paths infeasible.

Page 42: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

31/34

Path Coverage Criterion

Recall the path coverage criterion from class:

I a test set T such that, by executing P for each d in T,all paths leading from the initial to the final node of P’scontrol flow graph are traversed.

I Note that path coverage criterion → edge coveragecriterion.

Can you think of any weakness in just fulfilling this criterion?

I Generally, this criterion is impractical as in the generalcase the number of execution paths is very large. Thismakes traversing through all control paths infeasible.

Page 43: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

32/34

Path Coverage Criterion

Simple example:if (x % 2 = 0 ∨ y % 2 = 0) {

z = x/y;}

I How many test cases do we need to cover the conditioncoverage criterion?

I Many, many cases- we would need to test every possiblevalue of x and y that could make its way into theprogram. We could catch the division by 0 error frombefore.

I Note that this testing could end up taking a very longtime as programs grow and become more complex- it’ssimply infeasible in most cases.

Page 44: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

32/34

Path Coverage Criterion

Simple example:if (x % 2 = 0 ∨ y % 2 = 0) {

z = x/y;}

I How many test cases do we need to cover the conditioncoverage criterion?

I Many, many cases- we would need to test every possiblevalue of x and y that could make its way into theprogram. We could catch the division by 0 error frombefore.

I Note that this testing could end up taking a very longtime as programs grow and become more complex- it’ssimply infeasible in most cases.

Page 45: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

32/34

Path Coverage Criterion

Simple example:if (x % 2 = 0 ∨ y % 2 = 0) {

z = x/y;}

I How many test cases do we need to cover the conditioncoverage criterion?

I Many, many cases- we would need to test every possiblevalue of x and y that could make its way into theprogram. We could catch the division by 0 error frombefore.

I Note that this testing could end up taking a very longtime as programs grow and become more complex- it’ssimply infeasible in most cases.

Page 46: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

BackgroundInformation

StatementCoverage Criterion

Simple Example

Statement Coverage:RecordProcessor.java

Edge CoverageCriterion

Simple Example

Edge Coverage:RecordProcessor.java

ConditionCoverage Criterion

Simple Example

Path CoverageCriterion

Simple Example

Summary

33/34

Summary

I We covered a brief overview of statement coveragecriterion, edge coverage criterion, conditional coveragecriterion, and path coverage criterion and noted issueswith each.

I We can see the value in testing programs with multipletechniques. If code is missing some sort ofimplementation, white box testing won’t find it, butblack box testing will!

Page 47: White Box Testing Coverage Criterion Simple Example ... · I Recall that White Box Testing means using the information about the internal structure of the software to determine test

White BoxTesting

Zahra Ali

Appendix

References

34/34

References I

C. Ghezzi, M.Jazayeri, D.Mandrioli;Fundamentals of Software EngineeringPrentice Hall PTR, 2002.