The University of Lahore
A “W4” Category University
07/10/2020 1
Lecture 31
CHAPTER 4
The University of Lahore
A “W4” Category University
The University of Lahore
A “W4” Category University
07/10/2020 3
Use Case Testing
1. A black-box test design technique in which test cases are
designed to execute user scenarios.
2. A use case is a description of a particular use of the system by
an actor (a user of a system). Each use case describes the
interactions the actor has with the system in order to achieve a
specific tasks.
3. Use case are a sequence of steps that describe the interactions
between the actor and the system.
The University of Lahore
The University of Lahore
A “W4” Category University
The University of Lahore
The University of Lahore
A “W4” Category University
The University of Lahore
The University of Lahore
A “W4” Category University
07/10/2020 9
Experienced-Based Testing techniques
Error Guessing
“A test design technique where the experience of the tester is
used to anticipate where defects might be present in the
component or system.”
1. Success of error guessing is very much dependent on the
skills of the testers.
The University of Lahore
A “W4” Category University
Exploratory Testing
1. It is about exploring, finding out about the software, what it
does, what it doesn’t do, what work and what doesn’t work.
The University of Lahore
A “W4” Category University
The University of Lahore
A “W4” Category University
Definition of White-Box Testing
1. Testing based on analysis of internal logic (design,
code, etc.). (But
expected
results still come from
requirements.)
2. Also know as
structural testing.
3. White-box testing concerns techniques for
designing
tests; it is
not
a level of testing.
The University of Lahore
A “W4” Category University
07/10/2020 13
Structure-Based/White-Box/Glass-Box Testing
Design Techniques
The University of Lahore
A “W4” Category University
Code Coverage
The University of Lahore
A “W4” Category University
07/10/2020 15
Types of Coverage
The University of Lahore
A “W4” Category University
1. The statement coverage is also known as line
coverage or segment coverage.
2. The statement coverage
covers only the true
conditions.
3. Through statement coverage we can identify the
statements executed and where the code is not
executed.
The University of Lahore
A “W4” Category University
07/10/2020 17
1. Statement Coverage requires
that each statement will have
been executed at least once.
2. Simplest form of logic coverage.
The University of Lahore
A “W4Category University
Statement Coverage OR Statement Testing
Statement Coverage = Number of statements exercised
Total number of statements X 100
The University of Lahore
A “W4” Category University
07/10/2020 19
Example 1.1
1 READ A
2 READ B
3 C = A + 2 * B
4 IF C>50 THEN
5 PRINT “LARGE C”
6 ENDIF
TEST SET 1
Test 1_1: A = 2, B = 3 Test 1_2: A = 0, B = 25 Test 1_3: A = 47, B = 1
Test 1_4: A = 20, B = 25 (100% statement coverage)
83% statement coverage 2 READ statements
The University of Lahore
A “W4” Category University
1. If all statements in a program have been executed by
a set of tests then 100% statement coverage has
been achieved.
The University of Lahore
A “W4” Category University
07/10/2020 21
Example 1.2
READ X
READ Y
I F X>Y THEN Z = 0
ENDIF
To achieve 100% statement coverage of this code segment just
1 test case
is
required, one which ensures that variable X contains a value that is greater
than the value of variable Y.
Test Case_01:
X = 12 and Y = 10.
The University of Lahore
A “W4” Category University
Exercise 1.3
How many tests are required to achieve 100%
statement coverage?
1 test would be required to execute all three executable statements.
If our component consists of three lines of code we will execute all with one test case, thus achieving 100% statement coverage. There is only one way we can execute the code -
The University of Lahore
A “W4” Category University
07/10/2020 23
Exercise 1.4
The University of Lahore
A “W4” Category University
Exercise 1.5
How many tests are required to achieve 100% statement
coverage?
Therefore we will need three tests that answer 'yes' to 'if fuel tank empty‘
* Fuel tank empty AND petrol engine ( to execute line 3)
* Fuel tank empty AND NOT petrol engine( to execute line 5)
The University of Lahore
A “W4” Category University
Exercise 1.6
How many tests are required to achieve 100% statement
coverage?
In this example we have two separate questions that are being asked.
The tests have shown are
* A coffee drinker who wants cream
* A non coffee drinker who doesn`t want cream
Our 2 tests achieve 100% statement coverage, but equally we could have had 2 tests with:
The University of Lahore
A “W4” Category University
07/10/2020 27
Exercise 1.7
Draw flow diagram for this code:
READ P, Q
IF P+Q > 100 THEN
PRINT 'LARGE'
END IF
IF P>50
The University of Lahore
A “W4” Category University
Statement Coverage
The University of Lahore
A “W4” Category University
07/10/2020 29
if (x < y)
{
y = 0;
x = x + 1;
}
else
{
x = y;
}
4
1
2
3
x >= y x < y
x = y y = 0
x = x + 1
Statement coverage:
Cover every
reachable
statement
The University of Lahore
A “W4” Category University
areTheyPositive(int x, int y) {
if (x >= 0)
print(“x is positive”); else
print(“x is negative”); if (y >= 0)
print(“y is positive”); else
print(“y is negative”); }
There are smaller test cases which will give us statement coverage too:
T2 = {(x=12,y= 5), (x= 1,y=35)}
The University of Lahore
A “W4” Category University
07/10/2020 31
Exercise 1.10
assignAbsolute(int x) {
if (x < 0) x := -x; z := x; }
Consider this program segment, the test set T = {x=1} will give statement coverage, however not branch coverage
(x < 0)
x := -x
z := x
B0
B1
B2
Test set {x=1} does not execute this edge, hence, it does not give branch coverage true false
The University of Lahore
A “W4” Category University
The University of Lahore
A “W4” Category University
Decision Coverage OR Condition Coverage
Check if each possible branch from a decision
point has been executed
at least once.
The University of Lahore
A “W4” Category University
07/10/2020 35
Decision Coverage OR Condition Coverage
The University of Lahore
A “W4” Category University
1. The objective of decision coverage testing is to show all the
decisions within a component have been executed
at least
once.
The University of Lahore
A “W4” Category University
07/10/2020 37
Exercise 1.1
(x < 0)
x := -x
z := x
B0
B1
B2
Test set {x=1} does not execute this edge, hence, it does not give branch coverage
Test set {x= 1, x=2} gives both statement and branch coverage
The University of Lahore
A “W4” Category University
Exercise 1.2
if (x < y) { x = 5 * y; x = x + 3; }
else
y = 5; x = x+y;
(x < y)
x = 5 * y
x = x + 3 y = 5
x = x+y
B1 B
2
B0
B3
The University of Lahore
A “W4” Category University
07/10/2020 39
Exercise 1.3
1 READ A
2 READ B
3 C = A - 2 * B
4 IF C<0 THEN
5 PRINT “C negative”
6 ENDIF
TEST SET 2
The University of Lahore
A “W4” Category University
Exercise 1.4
The University of Lahore
A “W4” Category University
07/10/2020 41
SOLUTION
In this example there is one decision, and therefore 2 outcomes.
To achieve 100% decision coverage we could have two tests:
1- Age less than 17(answer 'yes')
2- Age equal to or greater than 17 (answer 'no')
The University of Lahore
A “W4” Category University
Exercise 1.5
The University of Lahore
A “W4” Category University
07/10/2020 43
Exercise 1.6
The University of Lahore
A “W4” Category University
SOLUTION
1 test for statement coverage
3 tests for decision coverage
SO you may think that 4 tests may be required to achieve 100% decision coverage ( two for each decision).
This is NOT the case! We can achieve 100% decision coverage with three tests - we need to exercise the 'Yes' outcome from the first decision ( line 1) twice, in order to next
exercise the 'Yes' and then the 'No' outcome from the supplementary question(line 2). We need a further third test to ensure we exercise the 'No' outcome of the first
decision( line 1 ).
The University of Lahore
A “W4” Category University
07/10/2020 45
Exercise 1.7
The University of Lahore
A “W4” Category University
SOLUTION
2 tests for statement coverage
3 tests for decision coverage
We have now introduced a statement that is associated with 'No' outcome of the decision on line 2.
The University of Lahore
A “W4” Category University
07/10/2020 47
Exercise 1.8
The University of Lahore
A “W4” Category University
SOLUTION
The University of Lahore
A “W4” Category University
07/10/2020 49
Exercise 1.9
1.
How many tests are required to achieve 100% statement coverage?
2.
How many tests are required to achieve 100% decision coverage?
The University of Lahore
A “W4” Category University
SOLUTION
The University of Lahore
A “W4” Category University
07/10/2020 51
Exercise 1.10
Read P Read Q
IF P+Q > 100 THEN Print “Large”
ENDIF
The University of Lahore
A “W4” Category University