A UML-Based Testing Approach Using Sequence Diagrams, Statecharts, - - PowerPoint PPT Presentation

a uml based testing approach
SMART_READER_LITE
LIVE PREVIEW

A UML-Based Testing Approach Using Sequence Diagrams, Statecharts, - - PowerPoint PPT Presentation

A UML-Based Testing Approach Using Sequence Diagrams, Statecharts, and OCL Constraints Dehla Sokenou TU Berlin Softwaretechnik Overview of the Test System test data test generation driver test case abstract test data generation test


slide-1
SLIDE 1

A UML-Based Testing Approach

Using Sequence Diagrams, Statecharts, and OCL Constraints

Dehla Sokenou TU Berlin Softwaretechnik

slide-2
SLIDE 2

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

2

test oracle test oracle integration executable test oracle

Overview of the Test System

test data test driver test execution test verdict UML model test data generation test oracle (UML) test oracle preparation abstract test cases test case generation

slide-3
SLIDE 3

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

3

Agenda

  • motivation
  • UML-based testing
  • test case generation
  • test oracle
  • aspects used for testing
  • summary and outlook
slide-4
SLIDE 4

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

4

Motivation (1)

  • open issue: testing object-oriented systems
  • problems: lack of specification, test code integration
  • UML widely used for modeling and specifying object
  • riented systems
  • artifacts created in the analysis and design phases provide a

good foundation for model-based testing

  • different views are modeled by using different diagram types
  • our idea: combining several diagram types for testing
  • test case selection based on UML diagrams
  • main information from sequence diagrams
  • additional information from state diagrams (UML statecharts)

and OCL constraints

slide-5
SLIDE 5

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

5

Motivation (2)

  • test code integration often expensive
  • test code needs privileged access to the SUT
  • version control
  • our idea: using dynamic aspects for testing
  • code is integrated in non-invasive manner
  • aspects have privileged access to the adapted system
slide-6
SLIDE 6

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

6

Example: Bank Account

isActive(): boolean isBlocked(): boolean isClosed(): boolean getBalance(): int activate() block() unblock() close() deposit(amount: int) withdraw(amount: int) status: int balance: int Account blocked active

  • pen

closed

activate close block unblock withdraw deposit deposit

protocol state machine

slide-7
SLIDE 7

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

7

Protocol State Machines

  • life cycle of objects
  • call events
  • no associated actions
  • implicit preconditions
  • observer methods

blocked active

  • pen

closed

activate close block unblock withdraw deposit deposit

slide-8
SLIDE 8

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

8

Test Case Generation

 based on sequence diagrams and UML statecharts

  • sequence diagrams
  • typical message sequences
  • communication between objects
  • statecharts (protocol state machines)
  • life cycle of objects
  • each sequence diagram = 1 test case
  • additional information from statecharts
  • initialization of test sequences
  • (test oracle)
slide-9
SLIDE 9

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

9

Test Case Generation: Example

a:Account x:Bank withdraw deposit b:Account close

blocked active

  • pen

closed

activate close block unblock withdraw deposit deposit TF 1) x{new}; a{new}; a.activate; b{new}; b.activate; x.close TF 2) x{new}; a{new}; a.activate; b{new}; b.activate; b.block; x.close sd1 close withdraw close deposit withdraw

active

close deposit

active

deposit

blocked

close withdraw

slide-10
SLIDE 10

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

10

Test Oracle

  • statecharts
  • implicit pre and post conditions
  • valid states and transitions
  • OCL constraints
  • explicit pre and post conditions
  • 2 variants of combination
  • 1. integration of OCL pre and post conditions into statecharts
  • 2. derivation of pre and post conditions from statecharts and

combination with explicit OCL constraints

slide-11
SLIDE 11

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

11

Test Oracle: Example (1)

blocked active

  • pen

closed

activate close block unblock withdraw deposit deposit

active credit debit

withdraw deposit deposit withdraw withdraw deposit

slide-12
SLIDE 12

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

12

Test Oracle: Example (2)

  • OCL: pre and post condition

context Account::withdraw(amount:int) pre: true post: self.balance = self.balance@pre - amount

active credit debit

withdraw deposit deposit withdraw withdraw deposit

  • protocol state machine
slide-13
SLIDE 13

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

13

Test Oracle: Example (3)

  • OCL: pre and post condition

context Account::withdraw(amount:int) pre: true post: self.balance = self.balance@pre - amount

  • statechart: pre and post condition

context Account::withdraw(amount:int) pre: self.isActive and (self.balance >=0 or self.balance <0) post: ((self.balance@pre >= 0 implies self.balance >= 0 or self.balance < 0) and (self.balance@pre < 0 implies self.balance < 0)) and self.isActive

slide-14
SLIDE 14

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

14

Test Oracle: Example (4)

  • statechart: derivation of pre and post condition

context Account::withdraw(amount:int)

pre: self.isActive and (self.balance >=0 or self.balance <0) post: ((self.balance@pre >= 0 implies self.balance >= 0 or self.balance < 0) and (self.balance@pre < 0 implies self.balance < 0)) and self.isActive

target states active credit debit

withdraw deposit deposit withdraw withdraw deposit

source states state invariants

  • f source states
slide-15
SLIDE 15

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

15

Test Oracle: Example (5)

  • resultant pre and post condition

context Account::withdraw(amount:int)

pre: true and self.isActive and … post: ((self.balance = self.balance@pre - amount) and (self.balance@pre >= 0 implies self.balance >= 0 or self.balance < 0) and (self.balance@pre < 0 implies self.balance < 0))) and self.isActive

OCL statechart active credit debit

withdraw deposit deposit withdraw withdraw deposit

slide-16
SLIDE 16

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

16

Test Code Integration (1)

  • integration of test oracles into the SUT
  • aspect-oriented language: Object Teams
  • generation of executable statecharts
  • compilation of OCL constraints
  • advantages
  • source and byte code of SUT not changed
  • aspects as roles with own state
  • tight coupling between aspect and role object
  • observer pattern already implemented (method calls are

forwarded to aspect)

  • privileged access to the SUT
slide-17
SLIDE 17

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

17

Test Code Integration (2)

  • executable statechart with Object Teams
  • statechart as role of object under test
  • one team for each statechart level
  • dynamic aspect activation for statechart hierarchy

implementation

  • more teams for OCL constraints and logging
  • bject

under test statechart notify event calls check state

slide-18
SLIDE 18

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

18

Test Code Integration: Example

team class Account_OCL { class Account_Role playedBy Account { Account obj_$AT_$PRE; abstract boolean isActive(); isActive -> isActive; /* CallOutBinding */

 // also for clone and other query methods

pre_withdraw <- before withdraw; /* CallInBinding */ post_withdraw <- after withdraw; void pre_withdraw(int amount) { /* Implementation */

  • bj_$AT_$PRE = clone();

if (!pre) { // test failed } } void post_withdraw(int amount) {  } } }

slide-19
SLIDE 19

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

19

Summary

  • combination of different diagram types
  • test case generation from sequences and statecharts
  • test oracle derivation from statecharts and OCL constraints
  • information collected from different views
  • independent test oracle
  • easy extension by using other diagram types
  • aspect-oriented integration of test oracle
  • non-invasive integration
  • privileged access
slide-20
SLIDE 20

Dehla Sokenou - TU Berlin - Softwaretechnik A UML-Based Testing Approach

20

Outlook

  • integration of additional UML diagram types
  • class diagram
  • activity diagram
  • additional OCL constraints (beside pre, post conditions,

invariants)

  • derivation of test data from UML models
  • use of efficient techniques
  • e.g. DresdenOCL
  • industrial case study