Model Based Functional Testing using Pattern Directed FilmstripsTony ClarkCentre for Model Driven Software EngineeringThames Valley Universitytony.clark@tvu.ac.uk1
OverviewIndustry likes using models.Tests as part of requirements is a good idea.Industry does not like scary stuff.Can modelling:Incorporate testing.Make tests more diagrammatic.Be more exemplar-based.Do more stuff with use cases.2
Example Model3
Behaviour4
Testing Behaviour – Wood from Treesclass TestSalesSystem extends TestCase {  private s = new SalesSystem();  public void testAddContact() {    String name = “fredjones”;s.contact(name);boolean added = false;    for(Person p : s.contactsDB().getPeople())      if(p.getCID().equals(name))        added = true;AssertTrue(name + “ not added”,added);  }...}5
Testing Behaviour – Scary!context SalesSystem::contact(name:String)  pre:     not contactsDB.people->exists(p |         p.name = name)  post: contactsDB.people->exists(p |     p.name = name)6
Model Driven Testing7
Filmstrip Specification8
Snapshots: AccountsHaveCustomerssnapshotAccountsHaveCustomers {object:SalesSystem {    accounts = object:AccountsSystem {        accounts forall {rootobject:Account {            cid = ?cobject ?o:Customer {            cid = ?c          }        }      }orderSystem =object:OrderSystem {        customers exists {root?o:Customer {        } object      }  }}9
Language – Text matches GraphicsF ::= let V = S in F               local defs |  always S { F }               invariants |  F F                          sequences |  F*                           repetition |  step Op pre S post S         stepsOp ::= V(E*)                       operationsS ::= S and S                      logical and |  S or S                       logical or |  not S                        logical not |  S[V/V]                       renaming |  snapshot B                   snapshotsB ::= { ([root]O)* }               object setsO ::= object [V]:T { (Q|F)* }      objectsQ ::= V (forall | exists) B        quantificationF ::= V (= | <>) E                 slotsE ::= V | Int | Str | Bool | O     values10
ExampleletAccountsHaveCustomers = ...UniqueIds = ...inalwaysAccountsHaveCustomersandUniqueIds {     (step contact(?id:String)pre snapshot {rootobject:SalesSystem {contactsDB = object:ContactsDB {            people forall {rootobject:Person {                cid <> ?id              }            }          }      }postsnapshot {rootobject:SalesSystem {contactsDB =object:ContactsDB {                 people exists {rootobject:Person {                  cid = ?id                }             }           }        }  ... ship, register and placeOrder)*}11
DemonstrationDSL for testing in XMFRun against SalesSystem in JavaCaveats:Filmstrip languageOCL for snapshots (not this demo)No implementation mapping.12
ConclusionExtend UML for model based testing:Filmstrips (based on use cases)Snapshot patterns (based on object models)Semantics: sequences of object models.Testing:Generate candidate filmstripsRun against SUT (after implementation mapping)13

Ast 09

  • 1.
    Model Based FunctionalTesting using Pattern Directed FilmstripsTony ClarkCentre for Model Driven Software EngineeringThames Valley Universitytony.clark@tvu.ac.uk1
  • 2.
    OverviewIndustry likes usingmodels.Tests as part of requirements is a good idea.Industry does not like scary stuff.Can modelling:Incorporate testing.Make tests more diagrammatic.Be more exemplar-based.Do more stuff with use cases.2
  • 3.
  • 4.
  • 5.
    Testing Behaviour –Wood from Treesclass TestSalesSystem extends TestCase { private s = new SalesSystem(); public void testAddContact() { String name = “fredjones”;s.contact(name);boolean added = false; for(Person p : s.contactsDB().getPeople()) if(p.getCID().equals(name)) added = true;AssertTrue(name + “ not added”,added); }...}5
  • 6.
    Testing Behaviour –Scary!context SalesSystem::contact(name:String) pre: not contactsDB.people->exists(p | p.name = name) post: contactsDB.people->exists(p | p.name = name)6
  • 7.
  • 8.
  • 9.
    Snapshots: AccountsHaveCustomerssnapshotAccountsHaveCustomers {object:SalesSystem{ accounts = object:AccountsSystem { accounts forall {rootobject:Account { cid = ?cobject ?o:Customer { cid = ?c } } }orderSystem =object:OrderSystem { customers exists {root?o:Customer { } object } }}9
  • 10.
    Language – Textmatches GraphicsF ::= let V = S in F local defs | always S { F } invariants | F F sequences | F* repetition | step Op pre S post S stepsOp ::= V(E*) operationsS ::= S and S logical and | S or S logical or | not S logical not | S[V/V] renaming | snapshot B snapshotsB ::= { ([root]O)* } object setsO ::= object [V]:T { (Q|F)* } objectsQ ::= V (forall | exists) B quantificationF ::= V (= | <>) E slotsE ::= V | Int | Str | Bool | O values10
  • 11.
    ExampleletAccountsHaveCustomers = ...UniqueIds= ...inalwaysAccountsHaveCustomersandUniqueIds { (step contact(?id:String)pre snapshot {rootobject:SalesSystem {contactsDB = object:ContactsDB { people forall {rootobject:Person { cid <> ?id } } } }postsnapshot {rootobject:SalesSystem {contactsDB =object:ContactsDB { people exists {rootobject:Person { cid = ?id } } } } ... ship, register and placeOrder)*}11
  • 12.
    DemonstrationDSL for testingin XMFRun against SalesSystem in JavaCaveats:Filmstrip languageOCL for snapshots (not this demo)No implementation mapping.12
  • 13.
    ConclusionExtend UML formodel based testing:Filmstrips (based on use cases)Snapshot patterns (based on object models)Semantics: sequences of object models.Testing:Generate candidate filmstripsRun against SUT (after implementation mapping)13