Chapter 7 Dynamic Testing 01
Chapter 7 Dynamic Testing 01
3
Manageme 5 Standards
2 Life cycle Infrastructu
1 Overview nt and
components re
component Organizing
components
8 Test s
6 Static 7 Dynamic
manageme 9 Tools
tesing testing
nt
Dynamic techniques
Learning objectives
Explain the characteristics and differences between
specification-based testing, structure-based testing and
experience-based testing
Compare the terms test condition, test case and test
procedure
Write test cases from given software models using
techniques: equivalence partitioning, boundary value
analysis, decision tables, state transition testing
Write test cases from given control flows using techniques:
statement coverage, decision coverage
Slide 2
References
Dorothy Grahamet, Erik van Veenendaal, Isabel Evans, Rex
Black. Foundations of software testing: ISTQB Certification
Slide 3
1 2 3 4 5
6 7 8 9
Contents
Dynamic techniques
Test condition – Test case – Test
procedure
Black-box techniques
White-box techniques
Experience-based techniques
Choosing test techniques
Categories of dynamic techniques
Specification-based (black-box techniques)
view software as black-box with input and output
Experience-based
use the tester’s experience, knowledge and intuition
Slide 6
Where to apply?
Black box appropriate at
all levels but dominates Acceptance
Acceptance
higher levels of testing
White box used
System
System
predominately at lower
levels
Experience-based
Integration
Integration
techniques used when
there is no specification
or inadequate or out of Component
Component
date
Slide 7
Dynamic technique
Experience-based Specification-based
Structure-based
Error guessing Equivalence
Partitioning
Exploratory testing
Statement Boundary
Value Analysis
Decision
Decision Tables
Condition
Condition State
Combination Transition
Use Case
testing
Slide 8
1 2 3 4 5
6 7 8 9
Contents
Dynamic techniques
Test condition – Test case – Test
procedure
Black-box techniques
White-box techniques
Experience-based techniques
Choosing test techniques
Test process
Identify conditions
Slide 12
Task 3: specify test procedures
Slide 13
Test condition – Test case – Test procedure
Example: Check Login functionality
Test Test Case Pre- Test Procedure Input Expected
Condition Name cond Results
Check Login Check valid 1) Launch application User Name: Login must
functionality User Name 2) Enter User Name admin be
& Password 3) Enter Password Password: successfull
4) Click Login 123456
Slide 14
1 2 3 4 5
6 7 8 9
Contents
Dynamic techniques
Test condition – Test case – Test
procedure
Black-box techniques
White-box techniques
Experience-based techniques
Choosing test techniques
Black-box techniques
Based on specifications (thông số kỹ thuật) or models of
what the system should do
Known as specification-based techniques (kỹ thuật dựa
trên đặc tả)
Including both functional and non-functional aspects
Some techniques
equivalence partitioning
boundary value analysis
decision tables testing
state transition testing
use case testing
Slide 16
Equivalence partitioning
(EP)
Slide 20
Equivalence partitioning
Guidelines
If an input condition specifies a ‘must be’ situation
“first character of the identifier must be a letter”
{first character is a letter}, {first character is not a letter}
Slide 21
Example EP 1
Expected
from 18 to 50
not no
integer integer not numeric input
input
Slide 22
Example EP 1 (cont.)
Draw table of analysis
Condition Valid partition Invalid partition
Age integer between 18 and 50 <18
>50
not integer
not numeric
no input
Slide 23
Design test case
Write a new test case covering as many of the uncovered
valid equivalence classes as possible, until all valid
equivalence classes have been covered by test cases
Write a test case that covers one, and only one, of the
uncovered invalid equivalence classes, until all invalid
equivalence classes have been covered by test cases
Slide 24
Design test case for EP: Example
Table of analysis
Condition Valid partition Invalid partition
Age integer between 18 and 50 <18
>50
not numeric
not integer
no input
Test case design
Condition Test case name Inputs Expected results
Test on Test valid age Abc;20 Ok…
Age field
Test age<18 Abc;10 Message “Age must be >18”
Test age>50 Abc;60 Message “Age must be <50”
Test invalid characters Abc;ab Message “Age must be a numeric”
Test not integer Abc;21.5 Message “Age must be an integer”
Test null value Abc; Message “Age not allow null”
Slide 25
Example EP 2
The Golden Splash Swimming Center’s ticket price depends on
four variables: day (weekday, weekend), visitor’s status (OT = one
time, M = member), entry hour (6.00–19.00, 19.01–24.00) and
visitor’s age (up to 16, 16.01–60, 60.01–120).
Slide 27
Example EP 2: Solution (cont.)
Slide 28
Example EP 3
A program reads three numbers, A, B, and C, with a range [1,
50] and prints the largest number. Design test cases for this
program using equivalence class testing technique.
Slide 29
Boundary value analysis (BVA)
Slide 30
Example BVA 1
Expected
from 18 to 50
Slide 32
Example EP - BVA
Expected
from 18 to 50
not no
integer integer non-numeric input
input
Condition Valid Invalid Valid Invalid
Partition Partition Boundary Boundary
Age 18 - 50 < 18 18 17
> 50 50 51
Số thực
Không là kí tự số
Rỗng Slide 33
Design test case (for Age)
# Test case type Input Expected
Name Age result
1 to 30 years
Repayment:
Interest rate:
Total paid back:
Slide 35
Customer name 2-64 chars
Number
of
invalid 1 2 valid 64 65 invalid
character
s:
Valid characters A-Z, a-z, Invalid
space
Condition Valid Invalid Valid Invalid
Partition Partition Boundary Boundary
Number of 5 6 7
digits: invalid valid invalid
valid: non-zero
First
character: invalid: zero
Non
0-9 numeric
Valid characters:
Condition Valid Invalid Valid Invalid
Partition Partition Boundary Boundary
Account 6 digits and < 6 digits 5
number 1st non-zero digits
> 6 digits
7
6 digits and 1st digits
digit = 0
non-digit
null
Loan amount £500 to £9000
not
Type of number: integer integer
Condition Valid Invalid Valid Invalid
Partition Partition Boundary Boundary
Loan 500 – 9000 < 500 500 499
amount >9000 9000 9001
non
numeric
not integer
null Slide 38
Term of loan 1 to 30 years
not
Type of number: integer integer
Condition Valid Invalid Valid Invalid
Partition Partition Boundary Boundary
Term of 1 – 30 <1 1 0
loan >30 30 31
non
numeric
not integer
null Slide 39
Condition template
Conditions Valid Invalid Valid Invalid
Partitions Partitions Boundaries Boundaries
Customer 2 - 64 chars > 64 chars 2 chars 1 char
name not a name 64 chars 65 chars
null
Account 6 digits and
< 6 digits 5 digits
number 1st non-zero
> 6 digits 7 digits
6 digits and 1st
0 digits
digit = 0
non-digit
Loan amount 500 - 9000 < 500 500 499
>9000 9000 9001
non numeric
not integer
null
Term of loan 1-30 <1 1 0
>30 30 31
non numeric
not integer
null Slide 40
Design test case for loan application
# Test case name Input Expected result
1 Test valid partition Customer name= John H Repayment=
Account numer= 123456 Interest rate=
Loan amount= 600 Total paid back=
Term of loan= 2
… … … …
Slide 41
Exercise 2: Bank account
Suppose you have a bank account that the rate of interest
depending on the balance in the account: a balance in the
range $0 up to $100.00 has a 3%, a balance over $100.00
and up to $1000.00 has a 5%, and balances of $1000.00 and
over have a 7%. What valid partition, invalid partition, valid
boundary and invalid boundary might you use? What test
cases we design?
Slide 42
Solution: Bank account
Balance in account
Invalid Valid (for 3%) Valid (for 5%) Valid (for 7%)
-$0.01 $0.00 $100.00 $100.01 $999.99 $1000.00
Test Valid partitions Invalid Valid Invalid
conditions partitions boundaries boundaries
Slide 43
BVA with ‘open boundary’
One of the sides of the partition is not defined
How to test?
Go back to the specification (đặc tả)
Investigate (xem xét) other related areas of the system
Probably need to use an intuitive (trực quan) or experience-
based (dựa trên kinh nghiệm) approach to probe various
large values trying to make it fail
Slide 44
Exercise 3
A mail-order company selling flower seeds charges
£3.95 for postage and packing on all orders up to £20.00
value and
£4.95 for orders above £20.00 value and up to £40.00 value.
For orders above £40.00 value there is no charge for postage
and packing.
If you were using equivalence partitioning to prepare test
cases for the postage and packing charges what valid
partitions would you define?
What about non-valid partitions? What boundary values?
Design test cases.
Slide 45
Exercise 3: Solution
Orders
invalid valid valid (for £3.95) valid (for £4.95) valid (for £0)
Slide 48
Decision tables testing
A good way to deal with combination of inputs, which
produce different results
Decision table
Known as a 'cause-effect' table
A table showing combinations of input with their associated
output or action
Business Business Business Business
Rule 1 Rule 2 Rule 3 Rule 4
Condition T T F F
1
Condition T F T T
2
Condition T - F T
3
Action 1 Y N N N Slide 49
Decision tables testing A
B
T
T
T
F
F
T
F
F
Slide 50
Decision tables testing example 1
Car rental example:
The specification says: If Age is over 23 and the person has
a clean driving record, supply rental car, else reject.
Conditions/Input Rule 1 Rule 2 Rule 3 Rule 4
Age > 23 T T F F
Clean driving record T F T F
Action/Output
Supply rental car Y N N N
Slide 52
Decision tables testing example 2
Conditions R1 R2 R3 R4 R5 R6 R7 R8
Coupon (20%) T F T F T F T F
Action
Discount (%) X X 20 15 30 10 20 0
X: Error message
R3: must review specification
Slide 53
Decision tables testing example 2
Conditions R1 R3 R4 R5 R6 R7 R8
Coupon (20%) - T F T F T F
Action
Discount (%) X 20 15 30 10 20 0
Slide 54
Extending decision tables - 1
Slide 55
Extending decision tables - 2
Decision table with multiple actions
Decision tables may specify more than one action for each
rule
Example
Rule 1 Rule 2 Rule 3 Rule 4
Conditions
Condition-1 Yes Yes No No
Condition-2 Yes No Yes No
Actions
Action-1 Do X Do Y Do X Do Z
Action-2 Do A Do B Do B Do B
Slide 56
Extending decision tables - 3
A decision table with non-binary conditions
Rule 1 Rule 2 Rule 3 Rule 4
Conditions
Condition-1 0–1 1–10 10–100 100–1000
Condition-2 <5 5 6 or 7 >7
Actions
Action-1 Do X Do Y Do X Do Z
Action-2 Do A Do B Do B Do B
Slide 58
Solution - decision table
Conditions R1 R2 R3 R4 R5 R6 R7 R8
'over 60s' rail card? T T T T F F F F
with a child? T T F F T T F F
family rail card? T F T F T F T F
Action
Conditions R1 R2 R3 R5 R6 R7
'over 60s' rail card? T T T F F F
with a child? T - F T T F
family rail card? T F T T F -
Action
discount 50% 34% 34% 50% 10% 0%
Slide 59
Solution – test cases
# Input Expected outcome
1 John, with 'over 60s' rail card and 50% discount for both tickets
family rail card, traveling with his
son (age 10)
2 Rogers, with 'over 60s', traveling 34% discount (for Rogers only)
with his wife
3 Tom, with 'over 60s' rail card and 34% discount
family rail card
4 Anna, with family rail card, 50% for both tickets
traveling with her baby
5 Betty, no rail card, traveling with 10% discount for both tickets
his 5-year-old niece
6 Henry, no rail card No discount
Slide 60
Applicability and Limitations
Decision table testing can be used whenever the system
must implement complex business rules when these rules
can be represented as a combination of conditions and
when these conditions have discrete actions associated
with them
Slide 61
State transition testing
This technique is helpful where you need to test differrent
system transitions
system where you get a different output for the same input,
depending on current state and past state
Based on state transition diagram
Slide 62
State transition diagram
Called State Chart or Graph
There are four main components of the graph
eat
4) actions that result from transition card
Slide 63
Example
Entering a PIN to a bank account
Slide 64
State transition diagram
Example State diagram for enter PIN
Start eat
card
card inserted enter PIN PIN not OK PIN not OK PIN not OK
Wait
for 1st try 2nd 3rd
PIN try try
PIN OK PIN OK
PIN OK
access
to
account
Slide 65
Creating test cases
Test conditions can be derived from the state graph in
various ways
Four different levels of coverage
state coverage
event coverage
path coverage
transition coverage
Slide 66
State coverage
All states are visited at least once
Generally this is a weak level of test coverage
1 2
Start eat
card
card inserted enter PIN PIN not OK PIN not OK PIN not OK
Wait
for 1st try 2nd 3rd
PIN try try
PIN OK PIN OK
PIN OK
access
to
account
Slide 67
Event coverage
All events are triggered at least once
Also is a weak level of coverage
1
Start eat
card
card inserted enter PIN PIN not OK PIN not OK PIN not OK
Wait
for 1st try 2nd 3rd
PIN try try
PIN OK PIN OK
PIN OK
access
to
account
Slide 68
Path coverage
All paths are executed at least once
The strongest level of coverage but may not be feasible
If the state transition diagram has loops, then the number
of possible paths may be infinite
e.g. given a system with two states, A and B, where A
transitions to B and B transitions to A. A few of the possible
paths are:
A→B
A→B→A
A→B→A→B→A→B
A→B→A→B→A→B→A
...
and so on forever.
Slide 69
Transition coverage
All transitions are exercised at least once
Good level of coverage without generating large
numbers of tests
eat
Generally the one recommended
Start card
card
inserted enter PIN PIN not OK PIN not OK PIN not OK
Wait
for 1st try 2nd 3rd
PIN try try
PIN OK
PIN OK
access
PIN OK to
account Slide 70
Testing for invalid transitions
Using state table as an intermediate step
list all the possible states and all the possible events: states
are listed on the left side of the table, events that cause
them on the top (or vice versa)
each cell represents the state system will move to when the
corresponding event occurs
thiswill include events that are not expected to happen in
certain states invalid transitions from that state
Test cases are usually derived from the state table
depending on the system risk, create test cases for some or
all of the invalid state/event pairs to make sure the system
has not implemented invalid paths
Slide 71
State table example
Example of state table for the PIN entering
Slide 72
Design test cases
# Test Step/Substep Expected Result
In all cases, the ATM starts in the
waiting for PIN
1 1. Insert card Prompts for PIN
2. Enter valid PIN Access account
2 1. Insert card Prompts for PIN
2. Enter invalid PIN (1st try) Reprompts for PIN
3. Enter valid PIN Access account
3 ... ...
Slide 73
State transition testing exercise
Scenario: A website shopping basket starts out as empty. As
purchases are selected, they are added to the shopping
basket. Items can also be removed from the shopping basket.
When the customer decides to check out, a summary of the
items in the basket and the total cost are shown. If the
contents and price are OK, then you leave the summary
display and go to the payment system. Otherwise you go
back to shopping (so you can remove items if you want).
a. Produce a state diagram showing the different states and
transitions. Define a test, in terms of the sequence of states,
to cover all transitions.
b. Produce a state table. Give an example test for an invalid
transition.
Slide 74
Solution - State diagram
Design a test cover all transitions?
basket
empty add item
(S1)
add item
remove
last item
Shopping check out
(S2)
remove item
summary OK
not OK & cost (S3)
Payment
(S4) Slide 75
Solution - State table
Slide 76
Applicability and Limitations
State-Transition diagrams are not applicable when the
system has no state or does not need to respond to real-
time events from outside of the system
Slide 77
Use case testing
A technique that helps identify test cases that cover the
whole system, on a transaction by transaction, from start
to finish
Use case is a sequence of steps that describe the
interactions between the actor and the system in order to
achieve a specific task
At least one test case for the main success scenario
At least one test case for each extension
Used widely in developing tests at system or acceptance
level
Slide 78
Use case testing
Use case component Description
Step Description
1 A: Inserts card
Main success scenario 2 S: Validates card and ask for PIN
A: Actor 3 A: Enters PIN
S: System
4 S: Validates PIN
5 S: Allows access to account
2a Card not valid
S: Displays message and rejects card
Slide 80
Black-box techniques - Disadvantages
Only a small number of possible inputs can actually be
tested
May leave many program paths untested
Without clear and concise specifications, test cases are
hard to design
There may be unnecessary repetition of test inputs if the
tester is not informed of test cases the programmer has
already tried
Slide 81
Learn more
Pairwise testing
Domain analysis testing
Slide 82
4
3
Manageme 5 Standards
1 2 Life cycle Infrastructu
nt and
Overview components re
component Organizing
components
6 8 Test
7 Dynamic 9s
Static manageme
testing Tools
tesing nt
Dynamic techniques
(cont.)
References
Dorothy Grahamet, Erik van Veenendaal, Isabel Evans, Rex
Black. Foundations of software testing: ISTQB Certification
Slide 90
1 2 3 4 5
6 7 8 9
Contents
Dynamic techniques
Test condition – Test case – Test
procedure
Black-box techniques
White-box techniques
Experience-based techniques
Choosing test techniques
White-box techniques
Structure-based approach
based on the internal structure of a component or system
also called glass-box techniques
Slide 92
White-box techniques
Some techniques
control flow testing
statement testing
decision testing
condition testing
decision/condition testing
path testing
Slide 93
Control-flow graph
Flow graphs for control structures
Slide 94
Control-flow graph - Example
Slide 95
Statement testing (Level 1)
A test design technique in which test cases are
designed to execute statements [ISTQB Glossary]
Statement coverage
the percentage of executable statements exercised by a
test suite ?
=
Slide 96
Statement coverage example 1
1
1 read(a)
2 IF a > 6 2 a>6
3 THEN T
F
4 b=a 3
5 ENDIF
print b 4
ow many test cases to get 100% statement coverage?
5
# Condition Input Line number excuted Expected result
1 a>6 7 1,2,3,4,5 7 (not from code)
Slide 97
Statement coverage example 2
Slide 98
Statement coverage example 2 - Solution
1-4
A>B
5
F T
B>C A>C
11 6
T F T
F
12 9 7
14
15
Slide 99
Statement coverage example 2 - Solution
Design test case
Slide
100
Statement coverage exercise
A program evaluates grades for students:
If StudentScore<=39, print "Fail".
If StudentScore between 39 and 60,
print “Pass”
If StudentScore between 59 and 80,
print “Merit”
If StudentScore>79, print “Distinction”
a. How many test cases will you need to
achieve 100% statement coverage?
Design test case.
b. Suppose we ran two test cases:
StudentScore = 50 and StudentScore = 30,
which lines of pseudo code will not be
exercised? How much is statement
coverage?
Slide
101
Statement coverage exercise: Solution
Slide
102
Statement coverage problems
Statement coverage can be achieved without branch
coverage
important cases may be missed
Slide
103
Decision testing (Level 2)
A test design technique in which test cases are designed to
execute decision outcomes [ISTQB Glossary]
decision: a logical expression which can be composed of
several logical operators like "or", "and", "xor"
decision outcome: each exit from a decision
two or more possible decision outcomes False
?
IF A > 1 decision True
IF A > 1 AND X = 2
Known as 'Branch testing', 'Basis path testing'
Slide
104
Decision testing (cont’d)
Decision coverage
percentage of decision outcomes exercised
=
specification-based may achieve only 40% to 60% decision
coverage
typical ad hoc testing achieves 20%
100% decision coverage guarantees 100% statement
coverage, but not vice versa
How to get 100% decision corverage?
Find out the minimum number of paths which will ensure
covering of all the edges
Slide
105
Decision testing example 1
Read A
IF A > 0 THEN Read
IF A = 21 THEN
Print “Key” Yes Yes
ENDIF A>0 A=21
ENDIF No No
Print
Minimum tests to
3
achieve with decision
coverage: ____
# Cases Inputs Expected result
End
1 A>0(F) A=-5 No message
2 A>0(T) and A=21(F) A=10 No message
3 A>0(T) and A=21(T) A=21 Message “Key” Slide
106
Decision testing example 2
Read A Yes
Read A<0 Print
Read B
IF A < 0 THEN No
Print “A negative” Print
ELSE
Print “A positive” Yes
ENDIF Minimum tests to achieve B<0 Print
IF B < 0 THEN 2
with decision coverage:
No
_____
Print “B negative” Print
ELSE
Print “B positive”
ENDIF End
Slide
107
Decision testing exercise 1
1 Read(CandidateAge)
2 If CandidateAge < 18
3 Then
4 Print (“Candidate is too young”)
5 Else
6 If CandidateAge > 30
7 Then
8 Print (“Candidate is too old”)
9 Else
10 Print(“Candidate may join Club 18–30”)
11 Endif CandidateAge<18
12 Endif CandidateAge>=18 and CandidateAge>30
CandidateAge>=18 and CandidateAge<=30
Slide
109
Decision testing exercise 2
a. 3 test cases
b. 83%
Slide
110
Solution exercise 2
Slide
111
Decision testing exercise 3
Slide
112
Solution exercise 3
Slide
113
Test
Suppose you are developing a software unit that will convert a non-signed 16 bit
binary number (in string format) to a decimal integer. For example,
BinaryToDecimal(“0000000000001111”) = 15. Draw CFG for this function.
Slide
114
Decision testing problems
Some branching decisions in programs are made not
based on a single condition but on multiple conditions
Decision coverage does not ensure that all entry-exit paths
are executed
A compound predicate is treated as a single statement
If n clauses, 2n combinations, but only 2 are tested
Example
Slide
116
Decision/Condition testing (Level 4)
Full condition coverage does not guarantee full decision
coverage
Example: if (x&&y)
{conditionedStatement;}
Using condition coverage, if we choose two test cases
(x=TRUE, y=FALSE and x=FALSE, y=TRUE), the
conditionedStatement will never be executed
Slide
117
Multiple condition testing (Level 5)
Known as ‘condition combination testing'
Requiring 2n test cases to achieve 100% coverage of a
decision containing n boolean operands
Example: A or (B and C)
Case A B C
1 FALSE FALSE FALSE
2 FALSE FALSE TRUE
3 FALSE TRUE FALSE
4 FALSE TRUE TRUE
5 TRUE FALSE FALSE
6 TRUE FALSE TRUE
7 TRUE TRUE FALSE
8 TRUE TRUE TRUE
Slide
118
Path testing (Level 6)
Design test cases based on what paths which should be
exercised
Path coverage
=
Slide
119
Paths through code 12 34
1 12 12 3
2 ?
? ? ? ?
Slide
120
Paths through code with loops
1 2 3 4 5 6 7 8 ….
Slide
121
White box techniques - Advantages
It permits direct checking of processing paths and
algorithms
It provides line coverage follow-up that delivers lists of
lines of code that have not yet been executed
It is capable of testing the quality of coding work
Slide
122
White box techniques - Disadvantages
It requires vast resources, much above those required for
black box testing
It cannot test the performance of software in terms of
availability, reliability, stress, etc.
The tester must have sufficient programming skill to
understand the code and its control flow
Control flow testing can be very time consuming because
of all the modules and basis paths that comprise a system
Slide
123
Unit Testing
In software engineering, unit testing is a test (often
automated) that validates that individual units of source
code are working properly.
A unit is the smallest testable part of an application. In
procedural programming a unit may be an individual
program, function, procedure, etc., while in object-
oriented programming, the smallest unit is a method,
which may belong to a base / super class, abstract class or
derived / child class.
Slide
124
Unit Testing
Slide
125
1 2 3 4 5
6 7 8 9
Contents
Dynamic techniques
Test condition – Test case – Test
procedure
Black-box techniques
White-box techniques
Experience-based techniques
Choosing test techniques
Non-systematic test techniques
Slide
129
1 2 3 4 5
6 7 8 9
Contents
Dynamic techniques
Test condition – Test case – Test
procedure
Black-box techniques
White-box techniques
Experience-based techniques
Choosing test techniques
Choosing test techniques
Each technique is good for certain things, and not as good
for other things
The best testing technique is no single testing technique:
each testing technique is good at finding one specific class
of defect
How can we choose the most appropriate testing
techniques to use? - Depend on internal and external
factors
Slide
131
Choosing test techniques (cont’d)
Internal factors
models used
tester knowledge or experience
test objective
documentation
life cycle model
Slide
132
Choosing test techniques (cont’d)
External factors
risk
customer or contractual requirements
type of system
time and budget
regulatory requirements
Slide
133