View
11
Download
0
Category
Preview:
Citation preview
Business Informatics GroupInstitute of Software Technology and Interactive Systems Vienna University of TechnologyFavoritenstraße 9-11/188-3, 1040 Vienna, Austriaphone: +43 (1) 58801-18804 (secretary), fax: +43 (1) 58801-18896office@big.tuwien.ac.at, www.big.tuwien.ac.at
Introduction to fUML and Test Language
Classes and Attributes
ClassA
- attributeX :int- attributeY :String
ClassB ClassC
+ anOperation(int) :boolean
*
+classA 1
+classB
*
+classC
1
Each class represents a concept in the modeled domain and has a
unique name
A class may have attributes whose types might be primitive data types (Integer, String, Boolean) or types
of other classes
A unidirectional relationship - referential attribute of an association owned by the
association or the source class
A bidirectional association An operation that can be invoked on an instance of a defining class – can be
specified by an activity diagram
2
Activities and ParametersAn activity is a specification of behavior as the coordinated execution of subordinate actions, using a control and data flow model.
input :Integer result :Integer
Activity
An activity may have input, output and return parameters
The parameters have corresponding activity parameter node on the boundary of the activity
Example taken from: “Programming in UML: An Introduction to fUML and Alf”, Tutorial for the OMG Executable UML Information Day Presented by Ed Seidewitz, 22 March 2011
3
Actions and Flows
input :Integer
result :Integer
actionA
object
actionB
result
activity doSomething (input: Integer) : Integer
An activity diagram is a graph structure consisting of activity nodes connected by activity edges.
An action is a fundamental unit of executable behavior within an activity.
A pin is an activity node that either accepts input to or provides output
from an action
A control flow specifies sequence of actions
An object flow provides a path of passing objects or data.
Example taken from: “Programming in UML: An Introduction to fUML and Alf”, Tutorial for the OMG Executable UML Information Day Presented by Ed Seidewitz, 22 March 2011
4
Control Nodes
initial
decision
actionD
actionAactionC
merge
actionE
final
actionB
fork
[false]
[true]
A merge node passes on any tokens it receives
An initial node generates a single control token
A control node is an activity node used to coordinate the flow of tokens between other nodes.
A decision node routes tokens based on a decision input value
An activity final node terminates the activity when it receives a token
Example taken from: “Programming in UML: An Introduction to fUML and Alf”, Tutorial for the OMG Executable UML Information Day Presented by Ed Seidewitz, 22 March 2011
5
Fork and Join Nodes
A fork node copies the tokens it is offered, and offers a copy on each
outgoing flow.
A join node waits for a token to be offered on all incoming flows and then
offers tokens on its outgoing flow.
fork join
actionA
actionB
actionC
actionD
Example taken from: “Programming in UML: An Introduction to fUML and Alf”, Tutorial for the OMG Executable UML Information Day Presented by Ed Seidewitz, 22 March 2011
6
Expansion regions
An expansion region is used to apply subordinate actions on all members of an input collection
An iterative expansion region applies nested behavior
sequentially to all collection elements
It can be also parallel
Example taken from: “Programming in UML: An Introduction to fUML and Alf”, Tutorial for the OMG Executable UML Information Day Presented by Ed Seidewitz, 22 March 2011
expansionRegion«iterative»
input
output
actionA
fork
actionBdecision
actionC
[true]
7
fUML Actions Table
Action Description
Creates an instance of a specified class.
Destroys the instance provided to the object input pin
Retrieves the instance which was set as context of the owner activity
Retrieves all existing instances of a specified class
Retrieves a value of a specified structural feature of an instance provided to object input pin
Adds a new value to the specified structuralfeature of an instance provided to object input pin
CreateObject
result
DestroyObject
object
ReadSelf
result
ReadExtent
result
ReadStructuralFeature
object result
AddStructuralFeatureValueobject
valueresult
8
fUML Actions Table Ctd.
Action Description
Removes a value of a specified structural feature of an instance provided to object input pin
Invokes execution of a specified activity
Invokes execution of a specified operation of a class (method of operation defined with an activity)
Creates a specified value instance
RemoveStructuralFeatureValue
object result
CallBehaviorAction
ValueSpecification
value
CallOperationAction
target
9
CatalogService.CreateItem
product :Product
item :Item
quantity :Integer
createItemCreateObject
resultsetProductToItem
AddStructuralFeatureValue
objectvalue
resultsetQuantityToItem
AddStructuralFeatureValue
objectvalue
result
Example activity: CreateItem of CatalogServiceAn activity specifying the behavior of the operation createItem() of the class CatalogService.
Creates an object of class Item
Sets the value to the quantity property of the item object
Creates a link between the item and the product
Product
+ name :String
Item
+ quantity :int
CatalogService
+ createItem(Product, int) :Item item_product
+product
1
10
Test Suite
import petstore.data.*import petstore.logic.*
scenario TestData[object productTD: Product{ Product.name=‘defaultProduct’; }object itemTD: Item{Item.quantity=10;}object catalogServiceTD: CatalogService{}link item_product {
source item_product.item = itemTD; target item_product.product = productTD;
}]
An import statement used to refer to UML model elements
A scenario is composed of several objects and links between those objects, and can be used for
providing input to the activities under test, and as expected result in state assertions
11
Test Case
test createItemTest activity CatalogService.CreateItem (product=TestData.productTD, quantity=10) {initialize TestData;
assertOrder CreateItem.setProductToItem, CreateItem.setQuantityToItem, *;
assertState always after action CreateItem.createItem until action CreateItem.setQuantityToItem {CreateItem.item != null;CreateItem.product = TestData.productTD;
}finally {
CreateItem.item::quantity = 2;check ‘itemProductSize’ on CreateItem.item;
}}
Assert order of execution: * and _
Temporal Quantifier Description
always Assertion should be true in all states of the defined period
immediately Assertion should be true in the first state after/until an action is executed
sometimes Assertion should be true in at least one state in the defined period
eventually Assertion should become true and remain true until the end of the defined period
finally is a shorthand for checking the last state after complete
execution of the activity
If there is a readSelf action in the activity then the context object should be specified:
e.g., on TestData.catalogServiceTD
12
OCL expressions
package datacontext Productinv defaultName: name = ‘defaultProduct’
context Iteminv itemProductSize: product->size()=1
context Orderinv noEmptyOrderLines: orderLines->forAll(item->collect(product)<>null)
endpackage
Name of a package for which the constraints are defined
Each constraint is defined within a scope of an element in the model
It’s possible to specify simple equality expressions on attributes and links
OCL standard functions such as iteration, selection, filtering, etc. that can be used in expressions
13
OCL Quick Reference
Type Values Operators and Operations
Boolean false, true or, and, not, <>
Integer …, -10, 0, 10, … =, <>, <, >, <=, >=, +, -, *, /
String ‘Carmen’ =, <>, size(), concat(String)
OclAny oclIsTypeOf(T), T.allInstances()
Collections size(), forAll(exp), select(exp)..
14
Test Results
Test Suite Run: 29-09-2014 15:00:05Activity: CatalogService.CreateItemActivity input: product = productTD; quantity = 10;
BruteForce check:Number of paths checked: 1Number of paths failed: 1
Failed Path: createItem, setProductToItem, setQuantityToItemOrder specification: setProductToItem, setQuantityToItem, *
Matrix validation result: FAIL
State assertion: ALWAYS AFTER createItem UNTIL setQuantityToItemState assertions checked: 2State assertions failed: 0
State assertion: ALWAYS AFTER setQuantityToItemState assertions checked: 1State assertions failed: 1
Expression: CreateItem.item::quantity = 2 / Actual was: 10
15
Recommended