State, State Graphs and Transition testing: state graphs, good & bad state graphs, state testing, Testability tips.
162 views
58 slides
Apr 22, 2025
Slide 1 of 58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
About This Presentation
State, State Graphs and Transition testing: state graphs, good & bad state graphs, state testing, Testability tips.
Size: 1.23 MB
Language: en
Added: Apr 22, 2025
Slides: 58 pages
Slide Content
Presented by:
Dr. B.Rajalingam
Associate Professor & HOD
Department of Artificial Intelligence and Data Science (AI&DS)
St. Martin's Engineering College
UNIT 4
State, State Graphs and Transition Testing
•Amoving automobilewhoseengineis runningcanhavethefollowingstates
withrespecttoitstransmission:
Reversegear
Neutralgear
Firstgear
Secondgear
Thirdgear
Fourthgear
•Like,Aperson’scheckbookcan havethewhatstateswithrespecttothebank
balance?(Equal,Lessthan,Greaterthan)
•A word processing program menu can be in the what states with respect to file
manipulation?(Copy,Delete, Rename,Create,Compress)
1.States(Cont’d)
•Whatever is being modeled is subjected to inputs. As a result of those inputs,
thestate changes,oris said tohavemadeaTransition.
•Transitionaredenotedbylinksthatjointhe states.
•Theinput thatcausesthetransitionaremarkedon thelink;that is, theinputs
arelinkweights.
•Thereis oneoutlinkfromeverystateforeveryinput.
•Ifseveralinputsinastatecauseatransitiontothesamesubsequentstate,
instead of drawing a bunch of parallel links we can abbreviate the notation by
listingtheseveralinputs asin:―input1, input2,input3………‖.
•A finite state machine is an abstract device that can be represented by a state
graphhavingafinitenumber ofstatesandafinitenumberoftransitions
betweenstates
2.InputsandTransitions
ThestategraphofFigureisinterpretedas follows:
1.Ifthesystemis inthe―NONE‖state,anyinputotherthanaZwillkeepitinthatstate.
2.IfaZ is received,thesystem transitionstothe―Z‖state.
3.Ifthesystemis inthe―Z‖stateandaZisreceived,itwillremaininthe―Z‖state.IfaCis
received,itwillgotothe―ZC‖ state;if anyother characteris received,itwillgobacktothe
―NONE‖statebecausethe sequencehas beenbroken.
4.AZ receivedinthe―ZC‖stateprogressestothe―ZCZ‖state,butanyothercharacterbreaks
the sequenceandcausesareturntothe―NONE‖state.
5.ACreceivedinthe―ZCZ‖statecompletesthesequenceandthesystementersthe―ZCZC‖
state. AZbreaksthesequenceandcausesatransitionbacktothe―Z‖state;anyother
character causesareturntothe―NONE‖state.
6.Thesystemstaysinthe―ZCZC‖stateno matterwhatisreceived.
2.InputsandTransitions(Cont’d)
•Anoutputcanbeassociatedwithanylink.
•Outputs aredenotedbylettersor wordsandareseparatedfrominputsby a
slashasfollows:―input/output‖.
•As always,outputdenotesanythingofinterest that’sobservableandisnot
restrictedtoexplicitoutputsbydevices.
•Outputsare alsolinkweights.
•If every input associated with a transition causes the same output, then
denoteditas:―input1, input2,input3…………../output‖
3.Outputs
•Bigstategraphsareclutteredandhardtofollow.
•It’smoreconvenienttorepresentthestategraphasatable(thestatetableor
statetransitiontable)thatspecifiesthestates,theinputs,thetransitionsand
theoutputs.
•Thefollowingconventionsareused:
Eachrow of thetablecorrespondstoastate.
Eachcolumncorrespondsto aninputcondition.
The box at the intersection of a row and a
column specifies the next state (the transition)
andtheoutput,if any.
4.State Tables
STATE OKAY ERROR
1 1/NONE 2/REWRITE
2 1/NONE 4/REWRITE
3 1/NONE 2/REWRITE
4 3/NONE 5/ERASE
5 1/NONE 6/ERASE
6 1/NONE 7/OUT
7 ... ...
•Stategraphs don’trepresenttime-theyrepresentsequence.
•Atransitionmighttake microsecondsor centuries;
•Asystemcouldbe inonestateformillisecondsand anotherforyears-thestate
•graphwould bethesamebecause ithasnonotion oftime.
•Although the finite state machines model can be elaborated to include notions
oftimein additiontosequence,such astimePetriNets.
5.TimeVersusSequence
6.1 Implementation andOperation
•Thepresentstateisfetchedfrommemory.
•The present input value is fetched. If it is already numerical, it can be used
directly;otherwise,itmayhavetobe encodedintoanumericalvalue,sayby
use ofacasestatement,a table,orsomeotherprocess.
•Thepresentstateand theinputcodearecombined (e.g.,concatenated) toyield a
pointer (row and column) of the transition table and its logical image (the output
table).
•Theoutputtable,eitherdirectlyorviaacasestatement,containsapointerto
theroutinetobeexecuted(theoutput)forthatstate-inputcombination.The
routineisinvoked(possiblyatrivialroutineifnooutputisrequired).
•Thesamepointerisusedtofetchthenewstatevalue,whichisthenstored.
Here are someprinciplesforjudging.
•The total number of states is equal to the product of the possibilities of factors
thatmake upthestate.
•For every state and input, there is a unique transition to exactly one state and
may be the samestateitself.
•Foreverytransitionthereisoneoutputactionspecified.Theoutputcouldbe
trivial,butatleastoneoutputdoessomethingsensible.
•Foreverystate thereis asequenceofinputs thatwilldrivethe systembackto
thesamestate.
RecognizingEquivalentStates
•There are two sets of rows
which, except for the state
names, have identical state
graphs with respect to
transitions and outputs.
The two sets can be
merged
Fig.MergedEquivalentStates
TransitionBugs–Unspecified andcontradictoryTransitions
•Everyinput-statecombinationmusthavea specifiedtransition.
•If the transition is impossible, then there must be a mechanism that prevents
theinput fromoccurringin thatstate.
•Exactlyonetransitionmust bespecifiedforeverycombinationofinputand
state.
•Aprogram canthavecontradictionsorambiguities.
•Ambiguities are impossible because the program will do something for every
input.
•Eventhe statedoes notchange,by definitionthisis atransitiontothesame
state.
TransitionBugs–DeadStates
•Adead stateis astatethatonceenteredcannot be left.
•This is not necessarilya bug but itissuspicious.
TransitionBugs–OutputErrors
•Thestates,transitions,andtheinputscouldbecorrect, therecouldbeno
dead orunreachablestates, buttheoutputforthe transitioncouldbe
incorrect.
•Outputactionsmustbe verifiedindependently of statesandtransitions
TransitionBugs–EncodingBugs
•Thebehaviorofafinite-statemachineisinvariantunderallencodings. That
is, saythatthestatesarenumbered1ton.
StateTesting–ImpactofBugs
•If a routine is specified as a state graph that has been verified as correct in all
details. Program code or table or a combination of both must still be
implemented.
•Abugcan manifestitselfasoneofthefollowingsymptoms:
•Wrongnumberofstates.
•Wrongtransitionsforagivenstate-inputcombination.
•Wrong outputforagiventransition.
•Pairs of statesor setsofstatesthat areinadvertently madeequivalent.
•Statesor setofstatesthataresplittocreateinequivalentduplicates.
•Statesor setsof statesthathavebecomedead.
•Statesor setsof statesthathavebecomeunreachable
StateTesting
What is State Transition Testing?
•StateTransitionTestingisapowerfultechniqueusedinblack-boxtestingtoensurethat
softwarebehavesasexpectedwhiletransitioningbetweendifferentstatesofasystem.
•First,itidentifiesafinitesetofstatesthatthesoftwarecanoccupy.
•Thenittestshowthesoftwaretransitionsbetweenthembasedondifferentinputconditions.
•Thistechniquecanbeappliedtovarioussystems,suchasvendingmachines,trafficlights,and
evenwebapplications,aslongastheirbehaviorcanbedefinedasafinitestatemachine.
•StateTransitionTestinginsoftwaretestinghelpstoensurethesoftware’sreliabilityand
robustness,especiallywhenthesoftwareisexpectedtohandlecomplexstatetransitions.
•Itcanalsobeusedtodetecterrorsthatmayoccurwhenthesystemmovesfromonestateto
another.
•Theapproachisusefulinreducingthenumberoftestcasesrequired,optimizingtestingtime,
andimprovingsoftwarequality.
What is State Transition Testing?
ThereareafewStateTransitionTestingTechniques.Theyareasbelow.
•StateTransitionDiagram:Itisagraphicalrepresentationofthesystem’sstatesandtheevents
thatcausethesystemtotransitionfromonestatetoanother.
•StateTransitionTable:Itisatabularrepresentationofthesystem’sstates,theeventsthat
causestatetransitions,andtheresultingactionsoroutputs.
•DecisionTableTesting:Itisatechniquethatusesatabletomapdifferentcombinationsof
inputstotheircorrespondingoutputs,makingiteasiertotestvariousscenarios.
•Cause-EffectGraphing:Itisatechniqueusedtoidentifyandtestdifferentinputcombinations
thatcancausespecificoutputsoreventstooccur.
•Stateflow:Itisagraphicaltoolusedtomodelandsimulatestate-basedsystems.
•Stateflowdiagramscanbeusedtodevelopandverifystate-basedalgorithmsandcontrollogic.
Use of State Transition?
•Whentestingasequenceofeventsthatoccurintheapplicationundertest.
•Whentheapplicationundertesthasadependencyontheevents/valuesinthepast.
•Whenasoftwareapplicationcanbedefinedbyafinitenumberofstates/inputvalues.
•Whentestinguserinterfaces.
•Userinterfacesmaytakedifferentformsdependingontheinputandtheymaytransition
betweenscreensi.e.states.
•Whentestingwebapplications.
•Webapplicationscanhavedifferentstatessuchaslogin/logout,addtocart,checkout,etc.,and
statetransitiontestingcantestthesestatestomakesurethattheapplicationbehavesas
intended.
•Whentestingmobileapplicationstotestonline/offlinestates,workflow,etc.
Four Parts of State Transition Diagram
1. Statesthe software can be.
•Represented by rectangles with rounded corners.
•A state is a situation or condition of a system.
•It is represented by a node in a state transition diagram.
•Each node represents a different state of the system.
2. Transitionsfrom one state to another
•Represented by arrows.
•A transition is a change in a state of a system that occurs when it responds to an event.
3. Eventsthat result in transitions
•Labeled above the applicable transition arrow.
•An event is an action or occurrence that triggers a change in the state of a system.
4. Actionsthat result from a transition from an event
•Could be represented by a message box.
•An action is a behavior that the system exhibits when it changes its state.
State Transition Diagram and State Transition Table
•Statetransitionscanberepresentedbyadiagramor/andatable.
•Astatetransitiondiagramisanillustrationofboxedtextsandarrows.
•Itisavisualrepresentationofthestatesandtheflowofthetransitions.
Change Mode:
When this mode is activated then the display mode moves from TIME to DATE.
Reset:
When the display mode is TIME or DATE, then reset mode sets them to ALTER TIME or
ALTER DATE respectively.
Time Set:
When this mode is activated, display mode changes from ALTER TIME to TIME.
Date Set:
When this mode is activated, display mode changes from ALTER DATE to DATE.
Transition States:
State Transition Diagram shows how the state of the system changes on
certain inputs.
It has four main components:
1. States
2. Transition
3. Events
4. Actions
State Transition Diagram
StateTesting–Principles
•The state transition table represents the states and transitions using a table where all the states
are listed on the left side and the events are described on the top.
•The state of the system after an event is represented by the rest of the table cells.
Start Event 1 Event 2
State 1 Action 1 State 2
State 2 Action 1 State 3
State 3 Action 1 Action 2
Action 1 – –
Action 2 – –
StateTesting–Principles
•Thestartingpointof statetestingis:
1.Defineasetofcoveringinputsequencesthatgetbacktothe initial
state whenstartingfromtheinitialstate.
2.For each step in each input sequence, define the expected next state, theexpected
transition,andthe expectedoutputcode.
•Aset oftests,then,consistsofthreesets ofsequences:
1.Inputsequences.
2.Correspondingtransitionsornext-state names.
3.Outputsequences.
StateTesting–LimitationsandExtensions
1.Simplyidentifyingthefactorsthatcontributetothestate,calculatingthetotalnumberof
states,andcomparingthis numbertothe designer’snotioncatchessomebugs.
2.Insistingonajustificationforallsupposedly dead,unreachable,andimpossiblestatesand
transitionscatchesa fewmorebugs.
3.Insistingonanexplicitspecificationof thetransitionand outputforeverycombination of
inputandstatecatchesmanymorebugs.
4.Asetof input sequencesthatprovidecoverageof allnodesandlinksisamandatoryminimum
requirement.
5.Inexecutingstatetests,itisessentialthatmeansbeprovided(e.g.,instrumentationsoftware)
torecordthesequenceof states(e.g.,transitions)resultingfromtheinputsequence and not
justtheoutputsthatresultfromtheinputsequence.
StateTesting–Getting the Data
•Statetesting,morethanmostfunctionaltest strategies,tendstohavealabor-intensivedata-
gatheringphase andtendsto need manymoremeetingsto resolveissues.
State Testing–Tools
•Therearetoolstodothesameforhardwarelogicdesigns.That’sthegoodnews.
•Thebadnewsisthatthesesystemsandlanguagesareproprietary,ofthehome-brewvariety,
internal,and/ornotapplicabletothegeneraluseofsoftwareimplementationsoffinite-state
machines
(iii)Switches,Flagsandunachievablepaths:
•Thefunctionalityofswitchesandflagsarealmostsimilarinthestatetesting.
•Switches or flags are used as essential tool for state testing to test the finite state machine in
every possible state.
•A flag or switch value is set at the initial process of finite state machine, and then this value is
evaluated and tested.
•Depending on its value the specific path is selected to find an easiest way for testing the finite
state machine.
•Mostly the switch or flag works on true or false condition.
TestabilityTips