Test Design Techniques
Test Design Techniques
Abdul Jaleel
Senior Testing Trainer
Talent Sprint
Content
Module 4 – Test Design Techniques
Introduction to Test Techniques
Code Coverage
The extent to which the code has been exercised by the test suite
is known as Code Coverage.
Functional/Requirements Coverage
The extent to which the requirements or functionality have been
exercised by the test suite is known as Requirements Coverage or
Functional Coverage.
Test Coverage – Introduction
Stronger structural
techniques (different
structural elements)
Increasing coverage
Measurement
Measurement
• Objective assessment of thoroughness of testing
with respect to use of each technique.
• Useful for comparison of one test effort to another
0 - 16 Don’t hire
55 - 99 Don’t hire
If not,
Test then which
it using valuesages:
all possible will you
0, 1,choose and
2, 3…, 98, why?
98, 99?
Equivalence Class Partition
If (applicantAge == 0) hireStatus="NO";
If (applicantAge == 1) hireStatus="NO";
If (applicantAge == 14) hireStatus="NO";
If (applicantAge == 15) hireStatus="NO";
If (applicantAge == 16) hireStatus="PART";
If (applicantAge == 17) hireStatus="PART"; How many
If (applicantAge == 18) hireStatus="FULL"; of you think
If (applicantAge == 19) hireStatus="FULL";
that the
...
If (applicantAge == 53) hireStatus="FULL";
code must
If (applicantAge == 54) hireStatus="FULL"; be written
If (applicantAge == 55) hireStatus="NO"; like this?
If (applicantAge == 56) hireStatus="NO";
...
If (applicantAge == 98) hireStatus="NO";
If (applicantAge == 99) hireStatus="NO";
If not,
Test then
it using which ages:
all possible values
0, 1, will
2, 3…,you choose
98, 98, 99? and why?
Equivalence Class Partition
Equivalence Class Partitioning
Is the Answer
Equivalence Class Partition
Pick up random values from
Divide (partition) the inputs
each partition and test the
and outputs
system
Deciding Valid and Invalid Test Data Ranges for Each Partition
0 1 99 100
ECP – Approach
Design-by Contract
Testing-by Contract
Defensive Testing
Design by Contract
What is Design-by Contract ?
A promise made to the customer about how we are going to design the
software
Invalid
Valid
Input Input !
Input Output
Invalid
Valid Output
Output
Module
Pre- Post-Conditions
Conditions
Gives
Design-by Contract
Testing-by Contract
Advantages
It enables a tester to select a subset of test inputs with a high
probability of detecting a defect
Disadvantages
It makes the assumption that the data in the same equivalence
class is processed in the same way by the system
ECP – Example 1
The Electricity bill computed by the service provider has a fixed
component as well as a running component. All customers are charged
at a rate of $40 flat as a fixed component. In addition to this, they would
be changed a running component . The rules for this are given below:
If the number of units consumed by the consumer is less than 10 units,
then the running cost is not charged for the consumer.
If the number of units is between 11 and 20, then the running cost is
charged at $1 per unit.
If the number of units is between 21 and 40, then the running cost is
charged at $2 per unit.
If the number of units exceeds 40, then the running cost is charged at $5
per unit.
Use Equivalence class partitioning to decide on the test cases to be
designed
ECP – Example 2
A user in a Small Savings investment bank may have fixed savings of
Rs 10,000 invested over a period of 45 days to 5 years. The interest
rate computed on the fixed savings is based on the duration of the
investment. The rules for this are given below:
If the duration of the investment is for 45 days, then the interest rate is
8% pa.
If the duration of investment is greater than 45 days but less than
1year, then the interest rate is 8.5% pa.
If the duration of investment is between 1 and 3 years, then the
interest rate is 9.5% pa.
If the duration is greater than 3 years, then the interest rate is 10.5%
pa.
Use Equivalence class partitioning to decide on the test cases to be
designed.
Boundary Value Analysis
BVA (Boundary Value Analysis)
A Technique Complimentary to
ECP
Boundary Value Analysis (BVA)
Boundary Value Analysis
BVA is the act of dividing the given input set by a relation into
groups or classes which is treated the same by the module or
which should produce the same result.
Boundary Value Analysis (BVA)
Faults tend to lurk near Boundaries are good place Test values on both sides
boundaries to find faults of boundaries
-1 0 1 2 98 99 100 101
Boundary Value Analysis (BVA)
Look at the highlighted parts in the code:
In the first instance, if condition is true, as per rule 1 system will show “Don’t
Hire”.
In the second instance, if condition is true, as per rule 2 system will show “Can
hire on a part-time basis only”.
Boundary Value Analysis (BVA)
Applicability
Typically be suited to systems in which much of the input data
takes on ranges of values or within sets
Advantages
Boundaries & conditions are the two major sources of defect
in software products. This technique aims to identify defects
in these areas.
Disadvantages
Does not work well for Boolean and logical variables.
BVA – Example 1
2-64 characters
Only 6 digits and 1st digit should be
non-zero
$500 to $ 9000
1 to 30 years
Minimum $10
1 2 64 65
A to Z
a to z
‘-’ and ‘_’
Valid Characters Within Boundary
Invalid
Conditions Valid Partitions Invalid Partitions Valid Bound Bound
2 – 64
Characters < 2 Characters 2 Char 1 Character
Customer
Name > 64 Characters 65 Character
Valid
Characters Invalid 64 Char
0 Character
Characters
BVA – Solution 1
Invalid Valid Invalid
5 6 7
Non-zero : Valid
First Character
Zero : Invalid
Invalid
Conditions Valid Partitions Invalid Partitions Valid Bound Bound
500 – 9000 < $500 500 499
> $9000
Account
Number Valid 0
9000 9001
Characters Non-Numeric
NULL
BVA – Solution 1
Invalid Valid Invalid
Invalid
Conditions Valid Partitions Invalid Partitions Valid Bound Bound
1 Year – 30 Years < 1 Year 1 Year, 2 Years 364 Days
> 31 Years
Term of Loan Valid 29 Years,
Characters Non-Numeric 30 Years 31 Years
NULL
BVA – Solution 1
Invalid Valid
$9 $10
Condition Entry
Rule – 1 Rule – 2 ------ Rule – p
Conditions
Condition Stub
Condition – 1
Condition – 2
------
Condition – m
Actions
Action – 1
Action
Stub
Action – 2
------
Action – n
Action Entry
Decision Table
Applicability
Can be used whenever the system must implement complex
business rules.
Advantages
Enables us to look at and consider “dependence,”
“impossible,” and “not relevant” situations and eliminate some
test cases.
Disadvantages
When the number of conditions is large then the decision
table becomes very huge and cumbersome.
Decision Table – Example 1
The following instructions were taken from a
University Examination Application Form. Examine
them and create a Decision Table to represent the
University Rules and thereby decide on the test cases to
be designed.
A candidate appearing for the exam should have a minimum 80%
attendance,
Has attended 3 internal tests with an average of 10 or more marks or
Has attended 2 internal tests with an average of 15 or more marks and
Has taken up the external examination and scored more than 35
marks
If the above conditions are fulfilled, then the student can be
considered as pass in that subject
Decision Table – Solution
Condition Entry
R R R R R R R R R9 R1 R11 R1 R13 R1 R15 R1
1 2 3 4 5 6 7 8 0 2 4 6
Condition Stub
Conditions
C1 T T T T T T T T F F F F F F F F
C2 T F T F T F T F T F T F T F T F
C3 T T F F T T F F T T F F T T F F
C4 T T T F F F F T T T T F F F F T
Actions
A1 T T T
Action
Stub
A2 F F F F F F F F F F F F F
Action Entry
Decision Table – Example 2
Suppose, You are to testing an insurance system to be used for
making decisions about whether policy can be granted to a
customer or not and accordingly, what discount should be
given to the customer?
Inputs
Conditions Rule 1
TC1 Rule 2 Rule 3 Rule 4 Rule 5 Rule 6 Rule 6 Rule 8
Married? N N N N Y Y Y Y
Drinks? N N Y Y N N Y Y
Good Student? N
Each Rule
Y
becomes
N
a TestY Case. N Y N Y
Expected
Actions Results Rule 1
TC1 Rule 2 Rule 3 Rule 4 Rule 5 Rule 6 … Rule P
Grant Policy Y Y Y Y Y Y Y Y
Discount 10 15 - 10 25 40 15 25
Decision Table – Example 3
Based on the specifications given below, construct a decision table and
choose appropriate action for each business rule. Also, develop the test
cases to cover all possible combinations:
Specifications:
A credit card processing system validates the cards based on the following rules:
• It will check for the following:
• Does the person hold the entered credit card, and is the other information
correct? (Is it a real account?)
• Is the credit card still active or has it been cancelled? (Active Account?)
The combinations of these conditions determine the possible actions from the
following:
• Should we approve the transaction?
• Should we call the card holder (e.g., to warn them about a purchase from a
strange place)?
• Should we call the vendor (e.g., to ask them to seize the cancelled card)?
State Transition Testing
State Transition Table – Introduction
State Transition Table
State-Transition diagrams are an excellent tool to capture
certain types of system requirements and to document
internal system design.
State Transition Table – Introduction
Is a condition in which a system is waiting for one
State or more events. It is generally represented by
Circles.
Represents a change from one state to another
Transition caused by an event. In the diagrams, Transitions
are represented by arrows.
Is something that causes the system to change
Event state. In the diagrams, Events are represented by
labels on a transition.
Is an operation initiated because of a state change. Actions
Action occur on transitions between the states and are represented
by the commands following the "/".
State Transition Table – Example 1
Consider a leave application system in an organization. An
employee can raise a request for a leave, and if he is eligible
for a leave (based on the number of days he has already
taken etc), the application is sent to the Manager for
approval. The manager then validates and approves or
rejects the leave based on the duration, reason for taking
leave.
Use State Transition diagram to represent the scenario and
derive the number of test cases for the same.
State Transition Table – Solution
State Transition Table – Example 2
Based on the following requirements, create a State Transition
Diagram and then derive the test cases:
• Provide information including departure and destination cities, dates
and times.
• A reservation agent uses this information to make a reservation.
• At this point, the Reservation is in Made state.
• The system creates and starts a timer.
• If the timer expires before the reservation is paid for, the reservation is
cancelled by the system.
• When money is paid, through initiation of the PayMoney action, the
system goes into “Paid” state.
– Events may have parameters associated with them. For example, Pay
Money may indicate Cash, Check, Debit Card or Credit Card.
State Transition Table – Example 2
• When the ticket is printed, the system goes into ‘Ticketed’ State
• Upon boarding the plane, the customer gives the boarding pass along
with the ticket, which signals that the ticket has been ‘Used’.
– Anything else after this state?
• If the Reservation is not paid on time, the PayTimer expires and the
reservation is cancelled for non-payment.
• A reservation may become cancelled, if the customer wishes to do so.
– This can happen prior to the payment or after the payment.
– If after the payment, a refund needs to be generated.
– The customer has to return printed ticket to the agent for refunding
it.
State Transition Table – Solution
Prin
t /Tic
ey
Pay Mon ket
Paid
Cancel/r
er im
Made Cancel
Ticketed
ay t
efund
art p
Give Ticket
Pay Timer
t
Expires
fo/s
urn
et und
In
R
l[ ref
Give
Cancelled BY e
Cancelled
Cust anc et]/
Non Pay C ck
Ti
Used
State Transition Table – Solution
Create a set of test cases such that all states are "visited" at
least once under test. P rint
Pay Money Tic /
ket
1
Cancel/r
2 Made Paid
3 Cance
Ticketed
l
er art
Give Ticket
Pay Timer
efund
t
Expires
fo/s
u rn
t nd
e In
e
tim
Cancelled
Cancelled BY
el[R refu
Giv
Cust nc et]/
pay
Non Pay a
C ck
Ti
Used
Cancel/r
3 Made Paid
4 Cancel
5 Ticketed
efund
Give Ticket
Pay Timer
er art
Expires
t
pay Info/s
urn
t nd
tim
Cancelled BY e
l[R refu
e
Cancelled e
Giv
Cust nc et]/
Non Pay a
C ck
Ti
Used
A strong coverage.
State Transition Table – Exercise 1
Consider a Purchase Order Management System. Each
purchase order which is raised by the sales team must be
initially approved by the manager of the employee and the
Head of Purchasing. Additionally, if the capital expenses are
more than $12,000, then it needs to be approved by the Head
of Finance.
Use State Transition diagram to represent the scenario and
derive the number of test cases for the same.
State Transition Table – Solution
White Box Testing
White Box
Dynamic Testing – White Box Testing
White box testing is a Program based testing to estimate the
completeness and correcteness of internal logic of each program
structure. Also called as Structural or Glass Box or Clear Box or
Open Box Testing.
Note:
To implement White Box testing techniques, testers should have
detailed programming skills.
White Box Testing – Process
Step 1 The SUT’s implementation is analyzed
Statement Coverage is
The percentage of executable statements that has been
exercised by a test suite
Example:
• Program has 100 statements
• Tests exercise 87 statements ?
• Then, the statement coverage = 87%
Decision Coverage is
The percentage of the decision outcomes that have been
exercised by a test suite
Example:
True
• Program has 120 Decision Outcomes
• Tests exercise 60 Decision Outcomes
• Then the Decision Coverage = 50% False
1 2 1 2 1 2 3
? ? ? ?
?
Path through the Code
1 2 3 4 5 6 7 8 ….
IF A = 21 THEN
A>0 A=21 Print
Print “Key” ? ? “Key”
ENDIF
ENDIF
END
Cyclomatic Complexity: 3
Statement Coverage: 1
Branch Coverage: 3
Statement & Decision Example 2
Read A
Read B Read A,
IF A > 0 THEN B
IF B = 0 THEN
Print “No values”
ELSE A>0 YES B=0 NO Print
Print B ? ? “B”
IF A > 21 THEN
Print A
ENDIF YES
YES
ENDIF NO A>21 Print
Print “No
ENDIF ? “A”
Values
NO
Cyclomatic Complexity: 4 END
Statement Coverage: 2
Branch Coverage: 4
Statement & Decision Example 3
Read A
Read B Read A,
IF A < 0 THEN B
Print “A negative”
ELSE
Print “A positive” A<0 YES
ENDIF Print A -ve
?
IF B < 0 THEN
Print “B negative”
NO
ELSE
Print “B positive” Print A +ve
ENDIF
Cyclomatic Complexity: 3
YES
B<0 Print B -ve
?
Minimum Tests to Achieve:
Statement Coverage: 2
NO
YES
B<0 Print B -ve
?
Cyclomatic Complexity: 3
NO
Minimum Tests to Achieve:
END
Statement Coverage: 1
Branch Coverage: 2
Statement & Decision Example 5
Read A,B
IF A < 0 THEN Read A,
Print “A negative” B
ENDIF
IF B > 0 THEN
Print “A positive” A<0 YES
ENDIF Print A -ve
?
NO
YES
B>0 Print A +ve
?
Cyclomatic Complexity: 3
NO
Minimum Tests to Achieve:
END
Statement Coverage: 1
Branch Coverage: 2
Use Case Testing
Use Case – Introduction
It the functionality of certain features of an application
which describes the interaction between the ‘Actor’,
‘Action’ and ‘Response’
Use Cases do not only describe the way that the product is
likely to be used, but also describe the way that the
processes flow through the system.
Administrator
Enroll
Actor
Is a user playing a role in the
system, seeking to use the
Student Drop system to accomplish
something worthwhile.
Use Case – Template
Use Case Component Description
Use Case Number Or Identifier <A unique identifier for this use case >
Use Case Name <The name should be the goal stated as a short
active verb phrase >
Primary Actor <Role name or description of the primary actor >
Preconditions <The required state of the system before the use case
is triggered >
Success End Conditions <The state of the system upon successful completion
of this use case >
Failed End Condition <The state of the system if the use case cannot
execute to completion >
Trigger <The action that initiates the execution of the use
case>
Main Success Scenario
Steps Actions Response
Alternate Scenario
Steps Actions Response
Use Case – Example 1
Use Case Component Description
Preconditions None
Basic Flow
Use Case – Example 1
Step Action System response
2a Course does not Display message
exist and exit
4a Section does not Display message
exist and exit
4b Section is full Display message
and exit
6a Student does not Display message
accept and exit
Alternate Flow
Use Case – Testable Flows
Exception Flow 2
Use Case
• Self Contained Alternate and
xception Flow 3
• Consistent format Exception Flows
Alternate Flow 4
Use Case – Testable Flows
Scenario 1
Error Guessing
Exploratory Testing Technique
Technique
Error Guessing