Test Ready UML Statechart Models: January 2006
Test Ready UML Statechart Models: January 2006
net/publication/221108561
CITATIONS READS
24 236
4 authors, including:
Rajesh Subramanyan
Siemens
25 PUBLICATIONS 483 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Rajesh Subramanyan on 04 June 2014.
75
provides test statements along state transitions in a test ready conditions, tasks and test statements along state transitions.
UML Statechart model so that a test generator can generate Events are modeled as data-flow graphs or as an extended
executable tests. The user may import existing UML Statechart context free grammar. Guard conditions, along state transitions,
models from a tool such as IBM Rational Rose or create the UML are used to specify a boolean condition that must be satisfied to
Statechart models using a standalone editor. select the transition. Tasks and Test statements may be specified
in states. When the test generator selects a state transition, the
task specified along the transition is executed which may set user
2. TEST READY UML STATECHART variables introduced in the model. The extended UML Statechart
MODELING model is called test ready, as the model is amenable for test
generation.
76
Test cases are instances of paths in the Test Ready UML model and also specifies a depth factor used as a limit to expand
Statechart Model. Note that an event modeled using a cycles, (b) The Test generator first generates paths that may have
combination of data selector node, data aggregate node and/ or a cycles and (c) for test case or test script generation, a cycle is
data generator node is an extended context free grammar. We expanded a random number of times limited by the depth factor.
refer to it as an extended context free grammar because guard Note that the cycle expansion step (c) is required only if a cyclic
conditions may be specified along the input links of data selector state transition is not guarded. If a cyclic state transition is
nodes. guarded as the cycle in Path 1 above, then cycle expansion is
carried out in step (b) above by the Test generator.
Definition of an Extended Context Free Grammar Model: A test
Ready UML Statechart model is an extended context free 4. EXTENDED CONTEXT FREE
grammar model. Events attached to state transitions are modeled
using a data selector node, a data aggregate node or a data GRAMMAR MODEL
generator node. A data generator node is a terminal in a CFG The variable Balance is initialized and it is updated whenever
(ValidPIN, InvalidPIN, ValidWithdraw, InvalidWithdraw, there is a deposit or a withdrawal by executing a task specified
NextTransaction, ExitTransaction), a data aggregate node is a along the respective transitions as shown below in the extended
non-terminal whose right hand side production consists of one or Context Free Grammar Model (of the Test Ready UML Statechart
more non-terminals and a data selector node is a non-terminal Model shown in Figure 1). The grammar below is a CFG
with alternate production rules (PIN, WithdrawalAmount, extended with guard conditions along state transitions (enclosed
ContinueTransaction, Operation). within square brackets), tasks and scripts along transitions or
alternate productions (for a detailed explanation about why a test
Definition of a Feasible Path: A feasible path is a path ready UML Statechart model is a CFG, refer to Section 3. Events
originating from the start node and terminating in a final state are shown in italics in the extended context free grammar below).
and for which all guard conditions along its state transitions are
satisfied during test generation. //ATM State Diagram Transitions
Start -> InsertCard CardInserted
The test generation problem thus reduces to determining feasible
CardInserted -> AcceptPIN
paths in the Test Ready UML Statechart model, which is an
AcceptPIN -> PIN ValidatePIN
extended context free grammar model, and creating instances of
ValidatePIN -> ATMTransactionBegin , if [Pin~Valid]
the paths. An event node (a data selector node which is a non-
-> Re-enterPIN , if [PIN~invalid]
terminal with alternate production rules) attached to a state
transition also contributes to a sub-path of a path from the initial
Re-enterPIN -> AcceptPIN, if [ NoOfTrials <= Limit]
state to a final state in the test ready UML Statechart model. The
-> AbortTransaction,
generation of paths starts from the start node with a state
if [NoOfTrials > Limit]
transition and exploring each one of the state transitions of the
ATMTransactionBegin -> Operation OperationSelected
next node, provided guard condition, if any, along a state
OperationSelected -> AcceptCheque, if [operation~Deposit]
transition is satisfied. Guard conditions are based on the input link
(Task: update var Balance)
(a grammar rule) selected for a data selector node (or a non-
-> AcceptAmount,
terminal). Or, a guard condition is a boolean condition on user
if [Operation ~ Withdraw]
variables introduced by the tester in the model such as Balance >
-> InformationDisplayed,
1000 and set by tasks, if specified, along state transitions. A guard
if [Operation~InformationDisplay]
condition may also be a combination of both the above forms. All
-> Exit, if [Operation ~ Exit]
guard conditions are evaluated during path generation. A depth-
first traversal over the graph, which is a combination of the UML
AcceptCheque-> ContinueTransaction ContinueNextTransaction
Statechart model and the event nodes represented as data-flow
graphs, is used in determining feasible paths. If a guard condition
InformationDisplayed ->
is not satisfied, backtracking may be required which initially starts
ContinueTransaction ContinueNextTransaction
by exploring other transitions or inlinks of the current node and if
none of them lead to a feasible path, then backtrack to the
AcceptAmount -> WithdrawalAmount CheckAmount
previous node and explore alternative state transitions or inlinks
of event nodes. If backtracking continues right upto the start node
CheckAmount -> InsufficientBalance ,
or root node without finding any feasible paths, the test generator
if [WithdrawalAmount >= Balance]
reports that it cannot find any more feasible paths.
-> DispatchAmount ,
Cycles are detected by maintaining a list of the nodes visited if [WithdrawalAmount < Balance]
already in the path formed so far and if the next node is already
present in the list of visited nodes of the path prefix, the cycle is InsufficientBalance -> AcceptAmount
marked. Once a state transition from the current node resulted in a
cycle with a node already visited, then an alternate transition from DispatchAmount->
the current node may terminate the path ending in a final state. ContinueTransaction ContinueNextTransaction
Such a path has one or more cycles marked. (Task: update var Balance)
The tool built based on Test Ready UML Statechart models has
three phases (a) Tester creates a Test Ready UML Statechart ContinueNextTransaction ->
77
ATMTransactionBegin, if [ContinueTransaction~Yes] transition, pathPrefix#transition) detects the alternate transition(s)
from the node through which a final state can be reached. The
ContinueNextTransaction -> function considers different paths that may arise, if multiple state
ReturnCard, if [ContinueTransaction~No] transitions from node participate in cycles.
ReturnCard -> End The path generation algorithm is based on depth-first traversal.
//Events used in ATM example and their grammar Rules PathGen(node, pathPrefix )
78
6. TEST SCRIPT GENERATION IsAtmAwaitingPinEntry(). These boolean functions provide an
Consider the path access to the current state of the running ATM Software. The test
execution environment may be visualized as consisting of a thread
Start -> (event: InsertCard) -> CardInserted -> {AcceptPIN -> running ATM Software itself and another running a test case (the
(event: PIN) -> ValidatePIN -> guard condition: [PIN ~ Invalid] synchronization code is not shown).
-> Re-enterPIN -> guard condition: [NoOfTrials <= Limit]}
-> guard condition: [NoOfTrials > Limit] -> AbortTransaction //---------Start of TestCase1----------
A test case is an instance of a path in the model. The tester class TestCase1
provides along a state transition in the Test Ready UML {
Statechart model in Figure 1 just the portion of the test case or TestCase1()
script that should be emitted, if the state transition is a part of the {
path from which the test case under construction is instantiated. It try
may be noted that a state transition may be a part of two or more {
paths, for example, Start ->CardInserted, or, ValidatePIN -> int NoOfTrial=1;
ATMTransactionBegin. Test statements (say in Java) may be int limit=3;
specified along only chosen state transitions or as a part of chosen int balance=10000;
states to validate if the software under test reaches an expected
state on the occurrence of a specified event. The tester, however, if(!atmProbeFunction.IsAtmInInitialState())
should have a coherent view of the snippets of code specified {
along state transitions so that the part of the test code specified throw new Exception("Atm not initialized : failed");
along a state transition is coherent with the following test code in }
subsequent state transitions in a path. If a state transition is a part
of multiple paths, the tester has to ensure that the test statements if(!atmProbeFunction.AtmAwaitingCardInsertion())
provided along the common state transition are coherent for all {
paths containing the state transition. throw new Exception("Card not inserted: failed");
}
In state based testing, it is essentially state sequencing that is //Set Card ID
checked. The testing problem for each test scenario is to consider
the sequence of events specified by the corresponding path in the if(!atmProbeFunction.IsAtmAwaitingPinEntry())
Test ready UML Statechart Model (behavioral diagram) and {
verify that as each event occurs, the ATM Software reaches the throw new Exception("Pin entry : failed");
next state as specified by the Statechart. In general, a snippet of }
test code along a state transition checks if the Software Under
Test (ATM Software) has not reached the expected state. If for an if(NoOfTrials<=limit)
event that triggers a state transition, the Software Under Test does {
not reach the expected state, the implementation does not conform NoOfTrials++;
to the UML Statechart model. When a test is run, the test }
statements specified along a state transition throw an exception or
generate an error message under the condition that the Software if(!atmProbeFunction.IsAtmAwaitingPinEntry("2345"))
Under Test does not reach the expected state condition on the {
occurrence of the event along the state transition. throw new Exception("Pin entry : failed");
Consider the path }
Start -> (event: InsertCard) -> CardInserted -> {AcceptPIN -> if(NoOfTrials<=limit)
(event: PIN) -> ValidatePIN -> guard condition: [PIN ~ Invalid] {
-> Re-enterPIN -> guard condition: [NoOfTrials <= Limit]} NoOfTrials++;
-> guard condition: [NoOfTrials > Limit] -> AbortTransaction }
For the path shown above, the ATM Software implementation if(!atmProbeFunction.IsAtmAwaitingPinEntry())
may deviate from the expected behavior if it does not reach an {
expected state condition along anyone of the state transitions in throw new Exception("Pin entry : failed");
the path on the occurrence of the corresponding event. The ATM }
Software passes a test case instance of the above path only if the
implementation successfully satisfies all the conditions of the if(NoOfTrials<=limit)
intermediate states as per the model and finally reaches the {
condition satisfied by the state AbortTransaction. NoOfTrials++;
A sample test case in Java emitted as an instance of the above path }
is given below. To carry out model based testing based on State if(NoOfTrials>limit)
diagrams, the Software Under Test must be testable. For {
testability, the ATM Software provides a number of probe
functions such as IsATMAboutToAbortTransaction() or if(!atmProbeFunction.IsATMAboutToAbortTransaction())
79
{ already instantiated, tasks and / or test scripts along state
throw new Exception("Atm has not reached AbortTransaction : transitions. Alternatively, a tester may create a UML
failed"); statechart/test ready UML statechart from scratch for testing
} purposes instead of relying on the model used during the
else development cycle. Our methodology has been found effective in
{ creating test ready UML statechart models for modeling
commercial applications such as bank transactions or an event-
System.out.println("ATM Passed test"); driven system such as the audio system in a car. We have also
} seen that Test Ready UML Statechart models can be used to
} describe the behavior of Graphical User Interface systems and
} generate test scripts automatically that can be executed by GUI
catch(Exception e) Capture play-back tools without user intervention. Our future
{ research work shall focus on generation of tests from test ready
System.out.println(e.getMessage()); UML statecharts that use concurrency. A state diagram that has
} nested states is flattened before path or test generation.
}
}
10. ACKNOWLEDGEMENTS
The authors would like to thank Juergen Kazmeier, Marlon Vieira
//----------End of TestCase1----------
of Siemens Corporate Research, Princeton and Mukul Saxena of
Corporate Technology, India for their valuable support.
7. REGRESSION TESTING
For a new version of the software under test, if its dynamic
behavioral model changes, then the UML Statechart model
11. REFERENCES
[1] Chow,T.S. Testing Software design modeled by Finite-state
changes and hence the test ready UML Statechart model also
machines. IEEE Transactions on Software Engineering SE-
changes. A diff of the ECFG models provides information about
4, 3 (1978), 178-187.
the set of the paths that are not present in the previous Test Ready
UML Statechart model. [2] J.A.Whittaker and M.G.Thomason: “A Markov Chain
Model for Statistical Software Testing”, IEEE Transactions
on Software Engineering, 20(10): 812-824, October 1994.
8. COVERAGE
The concepts of structural coverage based on code exercised are [3] Khaled L.Fakih, Nina Yevtushenko, Gregor Von Bachmann:
well studied, for example, statement coverage, branch coverage FSM-based Incremental Conformance Testing Methods,
and path coverage. We state that path coverage in a test ready IEEE Transactions on Software Engineering. Vol 30,
UML statechart model is achieved if tests corresponding to all the Number 7, 425-436.
paths or sentential forms in the corresponding ECFG model are [4] Robert V Binder. Testing Object-Oriented Systems: Models,
generated. Wherever there are cycles present, we consider (base) Tools and Patterns, Addison-Wesley, 2000.
path coverage is achieved if each and every cycle in the paths of
[5] Teradyne TestMaster, http://www.teradyne.com
the state model is traversed or exercised at least once in the tests
generated. [6] Friedman G., Hartman A., Nagin K.,Shiran T., Projected
State Machine Coverage for Software Testing, Proceedings
of ISSTA 2002 International Symposium on Software Testing
9. DISCUSSION and Analysis (July 2002).
UML Statechart models are used in practice by designers and
developers for describing the dynamic behavior of event-driven [7] Baker P., Bristow P., Jervis C., King D., Mitchell B.,
systems. Test scenarios based on UML statechart models can be Automatic Generation of Conformance Test From Message
visualized as instances of paths in the model. However, for test Sequence Charts, 3rd SAM Workshop - "Telecommunication
generation purposes, what is required is event generation and Beyond The broader applicability of SDL and MSC",
capability that can capture different variations or characteristics of Aberystwyth, UK. 24-26th June 2002.
events. Just as there are tools being used by developers to create [8] Bassanieri F., Bertolino A., and Marchetti E., The Cow Suite
UML statechart models to describe the dynamic behavior of approach to planning and deriving test suites in UML
systems during the development cycle, there is a need for projects, Proceedings of the Fifth International Conference
corresponding models, methodologies and tools for testers. To on the Unified Modeling Language - the Language and its
address this need, we have defined a Test Ready UML Statechart applications UML 2002, LNCS 2460, Dresden, Germany,
model, which indicates the model is ready with information for a September 30 - October 4, 2002, p. 383-397.
test generator to be able to generate test scripts automatically from
[9] Supaporn Kansomkeat., Wanchai Rivepiboon., Automated-
it.
Genearting Test Case Using UML statechart diagrams, ACM
A tester may import UML Statechart models from a developer’s International Conference Proceeding Series; Vol 47,
tool such as IBM Rational Rose into the visual editor of our UML Proceedings of the 2003 annual research conference of the
Statechart test generation tool and then add necessary information South African institute of computer scientists and
or attributes such as event nodes, guard conditions along state information technologists on Enablement through
transitions based on the properties of the event nodes that are technology.
80
[10] Basanieri, F., Bertolino, A., Marchetti, E., Ribolini, A., [14] Offutt, J., and Abdurazik, A. 1999. Generating test cases
Lombardi, G., And Nucera, G. 2001. An Automated Test from UML specifications. In Proceeding of the 2nd
Strategy Based on UML Diagrams. In Proceeding of the International Conference on the Unified Modeling Language
Ericsson Rational User Conference, October 10-11, 2001, (UML99), Fort Collins, CO, October 1999.
Upplands Vasby Sweden. [15] Kim, Y.G., Hong, H.S., Cho, S.M., Bae, D.H., and Cha,
[11] Hartmann, J., Imoberdof, C., and Meisenger, M. 2000. S.D. 1999. Test cases generation from UML state diagrams.
UML-Based Integration Testing. In ISSTA 2000, Portland, In IEEE Software, 146(4): 1999, 187-192.
August 2000. [16] Pretschner A., Slotosch.O, Aiglstorfer.E., and Kriebel.S.
[12] Lionel C. Briand , Yvan Labiche, A UML-Based approach to March 2004. Model Based Testing for real--The inhouse
System Testing, Proceedings of the 4th International card case study in Journal of Software Tools for Technology
Conference on the The Unified Modeling Language, Transfer, ©Springer-Verlag 5(2-3): 140-157.
Modeling Languages, Concepts, and Tools , October 01-05,
2001, pp.194-208,
[13] Offutt, J., and Abdurazik, A. 2000. Using UML collaboration
Diagrams for Static Checking and Test Generation. In UML
2000, University of York, UK, 2-6 October 2000.
81