Chapter 12hossein/Teaching/Fa09/814/Lectures/... · Software Testing: A Craftsman’s Approach, 4th...
Transcript of Chapter 12hossein/Teaching/Fa09/814/Lectures/... · Software Testing: A Craftsman’s Approach, 4th...
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Chapter 12
Model-Based Testing
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Overview of Model Based Testing (MBT)
• An iterative process • Start by modeling the
System Under Test (SUT) • Derive test cases from
the model • Execute test cases
– Record coverage – Trace to model
• Modify model as needed • Repeat steps
testing
modeling
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Modeling the System Under Test (SUT)
• Models were developed to meet the needs of the systems being analyzed – issues inherent in the system must be expressed – Petersen’s Lattice presents a nice selection (but
dated) of behavioral models • The hard part—picking the “right” model,
– not too powerful – not too weak – “necessary and sufficient
• We will spend some time on Peterson’s Lattice and recent updates.
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
ExtendedPetri Nets
Message Systems
Semaphore (P, V) Systems
VectorReplacement
Systems
VectorAdditionSystems
Petri Nets UCLA Graphs
Marked Graphs
Finite State Machines
Peterson’s Lattice of Behavioral Models
James L. Peterson, Petri Net Theory and the Modeling of Systems, Prentice Hall, Englewood Cliffs, NJ, 1981
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
About Peterson’s Lattice • In mathematics, a lattice represents a “partial
ordering” in which one element is “greater than” an adjacent element.
• In Peterson’s Lattice, the ordering relation is “more expressive than”
• In his book, Peterson shows, for each edge in the lattice, an example that cannot be represented in the weaker system and can be represented in the stronger one.
• But, he wrote in in 1981.
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Petri Net 5, 6, 7
SemaphoreSystem
3, 4
MarkedGraph
1
Finite StateMachine
2
Expressive Capabilities in Peterson’s Lattice
• Numbers correspond to regions in the diagram – 1 data flow – 2 control flow – 3 conflict – 4 mutual exclusion – 5 fair scheduling – 6 communication – 7 synchronization
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Updating Peterson’s Lattice • Three of the four equivalent models (vector
replacement systems, vector addition systems, and UCLA Graphs) are seldom used.
• Petri nets are usually extended. • Message systems and semaphore systems are
generally language based. • BUT Peterson’s book predates David Harel’s elegant
StateChart notation.
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
ExtendedPetri Nets
Message Systems
Semaphore (P, V) Systems
VectorReplacement
Systems
VectorAdditionSystems
Petri Nets UCLA Graphs
Marked Graphs
Finite State Machines
StateCharts
Where do StateCharts Belong?
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
About StateCharts
• (see Chapter 4!) • Harel’s main goal was to combine the expressive
powers of Directed Graphs and Venn Diagrams. • StateCharts have
– a sense of hierarchy – ability to describe concurrent devices – memory – history – and a very expressive language on transitions
• Clearly more expressive than (most) extensions to Petri Nets.
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Extensions to Peterson’s Lattice
• Event-Driven Petri Nets – Jorgensen, 1985
“The use of mm-paths in constructive software development”, Dissertation, Arizona State University
– chapter 4 in this book • StateCharts
– David Harel, 1988 • UML StateCharts (after 1998) • Swim Lane Petri Nets
– DeVries 2013 • (see text for full references)
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Event-DrivenPetri Nets
UML StateCharts
Petri Nets
Swim Lane Event-Driven
Petri Nets
Swim Lane Petri Nets
?
Extensions to Peterson’s Lattice
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Sources of Behavioral Issues Behavioral Issue Source of Issue
sequence
Structured Programming selection
repetition
enable
Extended Systems Modeling Language
disable
trigger
activate
suspend
resume
pause
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Sources of Behavioral Issues (continued) Behavioral Issue Source of Issue
Conflict
Task Management
priority
mutual exclusion
concurrent execution
deadlock
context sensitive input events
Events multiple context output events
asynchronous events
event quiescence
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Expressive Capabilities of Selected Behavioral Models
Behavioral Issue
Decision Tables
Finite State Machines
Petri Nets
Event- Driven Petri Nets
Statecharts
sequence no yes yes yes yes selection yes yes yes yes yes repetition yes yes yes yes yes enable no no yes yes yes disable no no yes yes yes trigger no no yes yes yes activate no no yes yes yes suspend no no yes yes yes resume no no yes yes yes pause no no yes yes yes
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Expressive Capabilities of Selected Behavioral Models (continued)
Behavioral Issue Decision Tables
Finite State
Machines
Petri Nets
Event-Driven Petri Nets
State charts
conflict no no yes yes yes priority no no yes yes yes mutual exclusion yes no yes yes yes concurrent execution no no yes yes yes deadlock no no yes yes yes context sensitive input events yes yes no yes yes multiple context output events yes yes no yes yes asynchronous events no no no yes yes event quiescence no no no yes yes
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
“Procedure” for Model-Based Testing
• Understand application to be modeled • Identify behavioral issues in the application • Use previous slides to select “appropriate” model
– this may depend on staff talent – or existing development tools – or other immutable requirements
• Model the application • Use an engine to “execute” the model, thereby
identifying – interesting scenarios – automatically generated test case (skeletons)
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Example for Model-Based Testing
• Based on the Simple ATM system (SATM) • One thread: Correct PIN on first try • Finite State Machines decomposed into a hierarchy
– Uppermost Level • PIN Entry state
– PIN try states • Derived Port Event Sequence for Correct PIN on
first try • Expanded Essential Use Case for Correct PIN on
first try
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Uppermost Level SATM Finite State Machine S1: Idle
(Welcome Screen)
S2: PIN Entry
S3: Transactionprocessing
S4: AnotherTransaction?
S5: Close ATMSession
Invalid Card/screen 4
Valid Card/screen 2
Valid PIN/screens 5 then 6Invalid PIN/screen 3
3rd PIN attempt failedscreen 1
Withdrawals
BalanceInquiry Deposits
No/screen 14
Yes
Timeout screen 15
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
PIN Entry Finite State Machine
Valid PINscreen 5
Invalid PINscreen 3
S1: Idle
S2: 1st PIN try
S2: 1st PIN try
S2: PIN Entry
S4: 3rd PIN try
S3: TransactionChoice
Valid PINscreen 5
Valid PINscreen 5
Invalid PINscreen 3
Invalid PINscreen 1
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
PIN Try Finite State Machine
S3: Transaction Choice
1st digit echo ‘---*’
S1: Idle
S2.n: nth PIN try
S2.n.1: 1 digitreceived
S2.n.2: 2digitsreceived
S2.n.3: 3 digitsreceived
S2.n.4: 4digitsreceived
2nd digit echo ‘--**’
3rd digit echo ‘-***’
4th digit echo ‘****’
Enter key, Valid PINscreen 5
Enter key, Invalid PIN
S2.n.0: 0 digitsreceived
S2.n.6: Retrydecision
Cancel
Cancel
Cancel
Cancel
Cancel
Try n < 3screen 3
Try n = 3screen 1
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Derived Port Event Sequence for Correct PIN on first try
Port Input Event Port Output Event
Screen 2 displayed with ‘- - - -’
1st digit
Screen 2 displayed with ‘- - - *’
2nd digit
Screen 2 displayed with ‘- - * *’
3rd digit
Screen 2 displayed with ‘- * * *‘
4th digit
Screen 2 displayed with ‘* * * *’
Enter touched
Screen 5 displayed
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing
Expanded Essential Use Case for Correct PIN on first try
Use Case Name Correct PIN entry on first try Use Case ID EEUC-1 Description A customer enters the Pin number
correctly on the first attempt. Pre-Conditions 1. The expected PIN is known
2. Screen 2 is displayed Event Sequence
Input events Output events 1. Screen 2 shows '- - - - ' 2. Customer touches 1st digit 3. Screen 2 shows '- - - * ' 4. Customer touches 2nd digit 5. Screen 2 shows '- - * * ' 6. Customer touches 3rd digit 7. Screen 2 shows '- * * * ' 8. Customer touches 4th digit 9. Screen 2 shows '* * * * ' 10. Customer touches Enter 11. Screen 5 is displayed Post conditions Select Transaction screen is active
Software Testing: A Craftsman’s Approach, 4th Edition Chapter 12 Model-Based Testing Software Testing: A Craftsman’s Approach, 3rd Edition Model-Based Testing
Commercial Tools for Model-Based Testing (from Practical Model-Based Testing, by Mark Utting and Bruno Legeard)
Tool Name Company Web Link Conformiq Test Generator
Conformiq www. conformiq.com
LEIROS LTG/B and LTG/UML
LEIROS Technologies
www.leiros.com
Reactis Reactive Systems
www.reactive-systems.com
StateMate (also Rhapsody)
IBM http://pic.dhe.ibm.com/infocenter/rhaphlp/v7r5/index.jsp?topic=%2Fcom.ibm.rhapsody.designing.doc%2Ftopics%2Frhp_c_dm_rning_anm_models.html
TAU Tester IBM http://www-01.ibm.com/software/rational/
ZigmaTESTTools ATS www.atssoft.copm