Professional Documents
Culture Documents
Final 11 (65 To 68)
Final 11 (65 To 68)
Lecture No. 11
Module 65:
Model based testing
Model based Testing
What is a model?
A model is a description of a
system’s behavior.
Models are simpler than the
systems they describe.
Models help us understand
and predict system’s behavior.
For Testing:
State-machines as models
Specifications as models
e.g., UML diagrams
Formal Specifications as
models e.g., Object Z
…
Model based Testing
Specifications:
Conformance testing:
To confirm if an implementation conforms to its standard
External tester applies a sequence of inputs to IUT and verifies
its behavior
Issue1: preparation of conformance tests in coverage of IUTs all
aspects
Issue2: time required to run test should not be unacceptably
long
Two main limitations
Controllability: the IUT cannot be directly put into a desired
state, usually requiring several additional state transitions
Conformance Testing
conformance relation
abstract abstract
model of S model of I
assumptions/ assumptions/
test hypothesis test hypothesis
conformance relation
precise
implementation I
specification S
Model based Testing
Fault model:
A fault model is a hypothetical
model of what types of faults
may occur in an
implementation
Most fault models are
"structural", i.e. the model
is a refinement of the
specification formalism (or
of an implementation
model)
E.g. mutations of the
specification or of a
correct implementation
Model based Testing
Fault model:
It may be used to construct
the fault domain used for
defining what "complete test
coverage" means single fault
hypothesis (or multiple
faults)
A fault model is useful for the
following problems:
Test suite development for
given coverage objective
Formalization of "test
purpose“
coverage evaluation and
optimization (existing suite)
Diagnostics
Model based Testing
It is very important to
highlight that it is possible
to have a state machine
based model of:
a single class
a complete system
Let us consider some
examples:
State machine as model - Testing
Transitions:
– create, destroy
– actions that triggers the
transition
ex. Add, delete
State machine as model - Testing
Arranging transitions
Initial -> Empty: action = “create”
– e.g. “s = new Stack()” in Java
Empty -> Holding: action = “add”
Empty -> Full: action = “add”
– if MAXcapacity=1
Empty -> Final: action = “destroy”
– e.g. destructor call in C++, garbage collection in
Java
Holding -> Empty: action = “delete”
– if s.size() = 1
State machine as model - Testing
State machine as model - Testing
Fault types:
• Missing or incorrect
Transitions – new state is
legal but incorrect
Events – valid message
ignored
• Extra, missing or corrupt state
• Sneak path: messages are
accepted when they should not
• Illegal message failure
• Trap door: system cannot get
out of that state
State machine as model - Testing
Coverage Criteria:
We can choose one or more
of the following test
selection criteria:
All states – testing passes
through all states
All events – testing forces
all events to occur at least
once
All actions – testing forces
all actions to be produced at
least once
State machine as model - Testing
Test strategies:
Possible strategies
All round-trip paths
All transition sequences
beginning and ending in
the same state
All simple paths from initial
to final state
This strategy will help you to
find
All invalid or missing states
Some extra states
All event an action faults
Module 67:
State machine as model - Testing
State machine as model - Testing
We have seen:
How can we extract state
machine from code and
specifications
State machine
representation of a
system
Model based testing
using state machine as a
model
Lets have an example
State machine as model - Testing
Scenario:
XYZ Consulting was
requested to develop a
shopping cart for Marks
and Spenser (a leading
shopping mall in the UK)
and the following
requirements have been
identified.
The system would only
allow registered users to do
the shopping and
registration process is
already working.
State machine based testing – example
Scenario:
Your consultancy is
requested to implement
login to the system,
selection of items on sale
and updating them into the
cart.
Customers has to make ten
purchases in one go and
then system allows them to
verify their payment details
and the delivery address.
Customers can replace
items during the purchase
process and update
quantities.
State machine based testing – example
/fail
Identify User /fail
/pass
/start
Select Item Confirm Order
/reset /purchase
Idle
/continue Confirm
Add to Cart
Delivery Addr
#(Item) = 10 /proceed /proceed
/cancel Receive
Checkout
Payment
status = OK && Qty > ordered
State machine based testing – example
We adopt
S No Intent Inputs Exp Output Pre-Cond Post-Cond
State machine based testing – example
/fail
Identify User /fail
/pass
/start
Select Item Confirm Order
/reset /purchase
Idle
/continue Confirm
Add to Cart
Delivery Addr
#(Item) = 10 /proceed /proceed
/cancel Receive
Checkout
Payment
status = OK && Qty > ordered
State machine based testing – example
Test Suite
/pass
/start
Select Item Confirm Order
/reset /purchase
Idle
/continue Confirm
Add to Cart
Delivery Addr
#(Item) = 10 /proceed /proceed
/cancel Receive
Checkout
Payment
status = OK && Qty > ordered
State machine based testing – example
Test Suite
S No Intent Inputs Exp Output Pre-Cond Post-Cond
1 Invalid Enter U name Invalid user Idle State Idle State
user Enter Passwd
Press Enter
2 Valid Enter U name Valid User Idle State Select Item
user Enter Passwd
purchasi Press Enter Cart Empty
ng
/fail
Identify User /fail
/pass
/start
Select Item Confirm Order
/reset /purchase
Idle
/continue Confirm
Add to Cart
Delivery Addr
#(Item) = 10 /proceed /proceed
/cancel Receive
Checkout
Payment
status = OK && Qty > ordered
State machine based testing – example
S No Intent Inputs Exp Output Pre-Cond Post-Cond
1 Invalid user Enter U name Invalid user Idle State Idle State
Enter Passwd
Press Enter
2 Valid user Enter U name Valid User Idle State Select Item state
Test Suite