6. Model based testing (A)

Author
Affiliations

Gabor Arpad Nemeth

Eötvös Loránd University (Hungary)

Original material

This page is a work-in-progress, the original materials can be accessed at ik-elte-sharepoint

Please don’t forget that this link only works if you log into the university account, either into your e-mail or cloud service.

Agenda

Short agenda:

  1. Theory background of MBT (Model-based testing)
  2. FSM (Finite State Machine) models
  3. Editing specification models with GraphWalker Studio
  4. Generate simple test sequences with…
    • GraphWalker Studio and
    • Model >> Test >> Relax

Degree of automization

graph TD
    classDef sub opacity:0
    classDef note fill:#ffd, stroke:#ccb
    
     A(Degree of automatization) --> B(from the view of test execution) --> C(Manual / Automated)
  A --> D(from the view of the test design) --> E(Manually designed) --> F(Generated)
       
    subgraph subE [" "]
        E
        noteE[ Test cases are designed by a test engineer based on specification]
    end

    subgraph subF [" "]
        F
        noteF[ Test cases are generated automatically from a test model or from the specification -> MBT Model Based Testing]
    end
    
    class subA,subB,subC sub
    class noteA,noteB,noteC note


Model based testing

Conformance testing

  • Given
    • Specification model (white box)
    • Implementation model (black box)
  • Test if the implementation conforms to the specification?
    • I.E. determine if the two corresponding model descriptions are equivalent

graph TD
    classDef sub opacity:0
    classDef note fill:#ffd, stroke:#ccb
    
     A <--> B --> C
     B --> D 

    subgraph subA [" "]
        A
        noteE[Specification model]
    end

    subgraph subB [" "]
        B
        noteF[Implementation model]
    end

FSM (Formal specification model)

FSM-based conformance testing

graph TD
    classDef sub opacity:0
    classDef note fill:#ffd, stroke:#ccb
    
     A(Specification: FSM white box) <--> B(Implementation: FSM Impl)

graph TD
    classDef sub opacity:0
    classDef note fill:#ffd, stroke:#ccb
    
     A(Requirements) --> B(Specification FSM M) --> C(Implementation FSM M, SUT)
     B --> D[ Test suite: test case 1, ..., test case n]

graph TD
    classDef sub opacity:0
    classDef note fill:#ffd, stroke:#ccb
    
     A[Test suite] -->|Input| B(Implementation FSM Impl, SUT) -->|Observed output| C(Tester)
     A -->|Expected output| C
     C --> D{Verdict}
     

FSM exercise

  1. Explore the functionality of the given device and write a specification for it
  • The device has 2 LEDs (red and green), a 2-way switch and a press button
  • The 2-way switch turns the device off or on. When the device is turned on, the green LED lights up.
  • The button can be used to change which LED lights; red or green.
  • If no button is pressed for 7 secs the device changes the lights.
  1. Create FSM based on the specification
  • Create state transition table
  • Create state transition graph
  1. Design an input/output sequence to test all functionalities of the specification

Waiting for 7 seconds can be handled as special timeout input message

FSM exercise - solution graph

s_off s_off s_green s_green s_off->s_green switch on/green s_green->s_off switch off/ s_red s_red s_green->s_red timeout(7s)/red s_green->s_red press button/red s_red->s_off switch off/ s_red->s_green timeout(7s)/green s_red->s_green press button/green
Figure 1: State transition graph

FSM exercise - state transition table

Switch on Switch off press button wait for 7 secs
s_off s_green/green _ _ _
s_green _ s_off/_ s_red/red s_red/red
s_red _ s_off/_ s_green/green s_green/green

FSM exercise - solution example test sequence

Action (input) Desired output
switch on green
wait for 7 secs red
wait for 7 secs green
press button red
switch off _
switch on green
press button red
press button green
switch off _

Graphwalker

  • Open source, free MBT tool with GUI
  • Easy-to-use
  • Good documentation

Working process

  1. Creating a model
  2. Write adaptation code that interacts with the SUT
  3. Generate tests
  4. Executing tests

Graphwalker Studio - Installation and start

  1. Fetch the docker image by running docker pull graphwalker/studio
  2. Run the image docker run -ti --rm -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME/.Xauthority:/home/developer/.Xauthority --net=host --pid=host --ipc=host graphwalker/studio

Graphwalker Studio - Alternative installation and start

If the previous approach didn’t work one can do the following steps

  1. Download and install Java JDK
  • Set JAVA_HOME variable in the system env list if not set auatomatically
  1. Install model editor Graphwalker studio

After installation

  1. Click on graphwalker studio graphwalker-studio-4.3.2.jar
  2. Open a web browser and type http://localhost:9090/studio.html

Graphwalker Studio - Battery operated signal example