《软件测试技术:Part II Testing Fundamentals》由会员分享,可在线阅读,更多相关《软件测试技术:Part II Testing Fundamentals(213页珍藏版)》请在金锄头文库上搜索。
1、PartII:TestingFundamentalsfarucalgary.caSoftware Testing ContentsnTypesofsoftwaretestingnExaminingtheSpecificationnTestingtheSoftwarewithBlindersOnnExaminingtheCodenTestingtheSoftwarewithX-RayGlassesPart II: Testing Fundamentals TypesofsoftwaretestingTypes of testingnOnepossibleclassificationisbased
2、onthefollowingfourclassifiers:nC1:Sourceoftestgeneration.nC2:LifecyclephaseinwhichtestingtakesplacenC3:GoalofaspecifictestingactivitynC4:CharacteristicsoftheartifactundertestC1: Source of test generationC2: Lifecycle phase in which testing takes placeC3: Goal of specific testing activityC4: Artifact
3、 under testPart II: Testing Fundamentals ExaminingtheSpecificationContentsnGettingStartednPerformingaHigh-LevelReviewoftheSpecificationnLow-LevelSpecificationTestTechniquesGetting StartednTheSoftwareDevelopmentProcess:big-bang,code-and-fix,waterfall,andspiral.Ineachmodel,exceptbig-bang,thedevelopmen
4、tteamcreatesaproduct specificationfromtherequirementsdocumenttodefinewhatthesoftwarewillbecome.nTheonlywaytoassurethattheendproductiswhatthecustomerrequiredandtoproperlyplanthetesteffortistothoroughly describe the product in a specification.Getting StartednAnexcerptfromtheWindowsCalculator(seeFigure
5、4.1):nTheEditmenuwillhavetwoselections:CopyandPaste.Thesecanbechosenbyoneofthreemethods:pointingandclickingtothemenuitemswiththemouse,usingaccess-keys(Alt+EandthenCforCopyandPforPaste),orusingthestandardWindowsshortcutkeysofCtrl+CforCopyandCtrl+VforPaste.nTheCopyfunctionwillcopythecurrententrydispla
6、yedinthenumbertextboxintotheWindowsClipboard.ThePastefunctionwillpastethevaluestoredintheWindowsClipboardintothenumbertextbox.nAsatesteryoullalsohaveadocumentasatestableitem.Youcanuseittofindbugsbeforethefirstlineofcodeiswritten.Getting StartednBlack-BoxandWhite-BoxTestingnBlack-boxtestingissometime
7、sreferredtoasfunctional testingorbehavioral testing.nwhite-boxtestingissometimescalledclear-box testingGetting StartednStaticandDynamicTestingnStatictestingreferstotestingsomethingthatsnotrunningexaminingandreviewingit.nDynamictestingiswhatyouwouldnormallythinkofastestingrunningandusingthesoftware.G
8、etting StartednStaticBlack-BoxTesting:TestingtheSpecificationnYoucantestaspecificationwithstaticblack-boxtechniquesnomatterwhattheformatofthespecification.Itcanbeawrittenorgraphicaldocumentoracombinationofboth.Youcaneventestanunwrittenspecificationbyquestioningthepeoplewhoaredesigningandwritingtheso
9、ftware.Performing a High-Level Review of the Specification Thefirststepintestingthespecificationisnttojumpinandlookforspecificbugs.Thefirststepistostandbackandviewitfromahighlevel.Examinethespecforlargefundamentalproblems,oversights,andomissions.Performing a High-Level Review of the SpecificationnPr
10、etendtoBetheCustomernItsimportanttounderstandthecustomersexpectations.Rememberthatthedefinitionofqualitymeansmeetingthecustomersneeds.Asatester,youmustunderstandthoseneedstotestthatthesoftwaremeetsthem.nDontforgetaboutsoftwaresecuritywhenpretendingtobethecustomer.Performing a High-Level Review of th
11、e SpecificationnResearchExistingStandardsandGuidelinesnThedifferencebetweenstandardsandguidelinesisamatterofdegree.Astandardismuchmorefirmthanaguideline.nGuidelinesareoptionalbutshouldbefollowed.nCorporateTerminologyandConventions.nIndustryRequirements.nGovernmentStandards.nGraphicalUserInterface(GU
12、I).nSecurityStandards.Performing a High-Level Review of the SpecificationnReviewandTestSimilarSoftwarenOneofthebestmethodsforunderstandingwhatyourproductwillbecomeistoresearchsimilarsoftware.Thiscouldbeacompetitorsproductorsomethingsimilartowhatyourteamiscreating.nSomethingstolookforwhenreviewingcom
13、petitiveproductsincludenScale.nComplexity.nTestability.nQuality/Reliability.nSecurity.Low-Level Specification Test Techniques nSpecificationAttributesChecklistnAgood,well-thought-outproductspecification,withallitstscrossedanditsisdotted,haseightimportantattributes:nComplete.nAccurate.nPrecise,Unambi
14、guous,andClear.nConsistent.nRelevant.nFeasible.nCode-free.nTestable.Low-Level Specification Test TechniquesnSpecificationTerminologyChecklistnThespecmaygoontoclarifyorelaborateonthem,oritmayleavethemambiguousinwhichcase,youvefoundabug.nAlways,Every,All,None,Never.nCertainly,Therefore,Clearly,Obvious
15、ly,Evidently.nSome,Sometimes,Often,Usually,Ordinarily,Customarily,Most,Mostly.nEtc.,AndSoForth,AndSoOn,SuchAs.nGood,Fast,Cheap,Efficient,Small,Stable.nHandled,Processed,Rejected,Skipped,Eliminated.nIfThen(butmissingElse).Highlights of this chapter includenWhatisblack-boxandwhite-boxtestingnHowstatic
16、anddynamictestingdiffernWhathigh-leveltechniquescanbeusedforreviewingaproductspecificationnWhatspecificproblemsyoushouldlookforwhenreviewingaproductspecificationindetailPart II: Testing Fundamentals TestingtheSoftwarewithBlindersOnContents nDynamicBlack-BoxTesting:TestingtheSoftwareWhileBlindfoldedn
17、Test-to-PassandTest-to-FailnEquivalencePartitioningnBoundaryvalueanalysisnDecisionTableBasedtestingnTestgenerationfrompredicatesnStateTestingnOtherBlack-BoxTestTechniquesDynamic Black-Box TestingnYoureenteringinputs,receivingoutputs,andcheckingtheresults.Anothernamecommonlyusedfordynamicblack-boxtes
18、tingisbehavioral testingbecauseyouretestinghowthesoftwareactuallybehaveswhenitsused.nTodothiseffectivelyrequiressomedefinitionofwhatthesoftwaredoesnamely,arequirementsdocumentorproductspecification.nOnceyouknowtheinsandoutsofthesoftwareyoureabouttotest,yournextstepistostartdefiningthetestcases.Dynam
19、ic Black-Box TestingnTest cases arethespecificinputsthatyoulltryandtheproceduresthatyoullfollowwhenyoutestthesoftware.nSelectingtestcasesisthesinglemostimportanttaskthatsoftwaretestersdo.nImproperselectioncanresultintestingtoomuch,testingtoolittle,ortestingthewrongthings.nIntelligentlyweighingtheris
20、ksandreducingtheinfinitepossibilitiestoamanageableeffectivesetiswherethemagicis.Test-to-Pass and Test-to-FailnTherearetwofundamentalapproachestotestingsoftware:test-to-passandtest-to-fail.nWhenyoutest-to-pass,youreallyassureonlythatthesoftwareminimallyworks.nDesigningandrunningtestcaseswiththesolepu
21、rposeofbreakingthesoftwareiscalledtesting-to-failorerror-forcing.nAcommonclassoftestcasesisonethatattemptstoforceerrormessages.Youknowtheoneslikesavingafiletoafloppydiskbutnothavingoneinsertedinthedrive.Thesecasesactuallystraddlethelinebetweentest-to-passandtest-to-fail.EquivalenceclasspartitioningT
22、estselectionusingequivalencepartitioningallowsatestertosubdividetheinputdomainintoarelativelysmallnumberofsub-domains,sayN1,asshown(nextslide(a).Instrictmathematicalterms,thesub-domainsbydefinitionaredisjoint.Thefoursubsetsshownin(a)constituteapartitionoftheinputdomainwhilethesubsetsin(b)arenot.Each
23、subsetisknownasanequivalenceclass.Equivalence partitioningSubdomainsTheequivalenceclassesarecreatedassumingthattheprogramundertestexhibitsthesamebehavioronallelements,i.e.tests,withinaclass.ThisassumptionallowthetestertoselectexactlyonetestfromeachequivalenceclassresultinginatestsuiteofexactlyNtests
24、.Program behavior and equivalence classesTheentiresetofinputstoanyapplicationcanbedividedintoatleasttwosubsets:onecontainingalltheexpected,orlegal,inputs(E)andtheothercontainingallunexpected,orillegal,inputs(U).Eachofthetwosubsets,canbefurthersubdividedintosubsetsonwhichtheapplicationisrequiredtobeh
25、avedifferently(e.g.E1,E2,E3,andU1,U2).Faults targetedEquivalence class partitioning selects tests that target any faults in the application that cause it to behave incorrectly when the input is in either of the two classes or their subsets.Faults targeted (cont.)ConsideranapplicationAthattakesaninte
26、gerdenotedbyageasinput.Letussupposethattheonlylegalvaluesofageareintherange1.120.ThesetofinputvaluesisnowdividedintoasetEcontainingallintegersintherange1.120andasetUcontainingtheremainingintegers.All integers1.120Other integersExample 1Further,assumethattheapplicationisrequiredtoprocessallvaluesinth
27、erange1.61inaccordancewithrequirementR1andthoseintherange62.120accordingtorequirementR2.ThusEisfurthersubdividedintotworegionsdependingontheexpectedbehavior.Similarly,itisexpectedthatallinvalidinputslessthanorequalto1aretobetreatedinonewaywhileallgreaterthan120aretobetreateddifferently.Thisleadstoas
28、ubdivisionofUintotwocategories.Example 1 (contd.)All integers62-1201.61120Example 1 (contd.)Itisexpectedthatanysingletestselectedfromtherange1.61willrevealanyfaultwithrespecttoR1.Similarly,anytestselectedfromtheregion62.120willrevealanyfaultwithrespecttoR2.Asimilarexpectationappliestothetworegionsco
29、ntainingtheunexpectedinputs.Testsselectedusingtheequivalencepartitioningtechniqueaimattargetingfaultsintheapplicationundertestwithrespecttoinputsinanyofthefourregions,i.e.tworegionscontainingexpectedinputsandtworegionscontainingtheunexpectedinputs.Example 1 (contd.)Theeffectivenessoftestsgeneratedus
30、ingequivalencepartitioningfortestingapplicationA,isjudgedbytheratioofthenumberoffaultsthesetestsareabletoexposetothetotalfaultslurkinginA.Asisthecasewithanytestselectiontechniqueinsoftwaretesting,theeffectivenessoftestsselectedusingequivalencepartitioningislessthan1formostpracticalapplications.Theef
31、fectivenesscanbeimprovedthroughanunambiguousandcompletespecificationoftherequirementsandcarefullyselectedtestsusingtheequivalencepartitioningtechniquedescribedinthefollowingsections.EffectivenessConsiderthatwordCountmethodtakesawordwandafilenamefasinputandreturnsthenumberofoccurrencesofwinthetextcon
32、tainedinthefilenamedf.Anexceptionisraisedifthereisnofilewithnamef.Thisexampleshowsafewwaystodefineequivalenceclassesbasedontheknowledgeofrequirementsandtheprogramtext.Example 2beginString w, fInput w, fif (not exists(f) raise exception; return(0);if(length(w)=0)return(0);if(empty(f)return(0);return(
33、getCount(w,f);endUsingthepartitioningmethoddescribedintheexamplesabove,weobtainthefollowingequivalenceclasses.Example 2 (contd.)EquivalenceclasswfE1non-nullexists,notemptyE2non-nulldoesnotexistE3non-nullexists,emptyE4nullexists,notemptyE5nulldoesnotexistE6nullexists,emptyExample 2 (contd.)Notethatth
34、enumberofequivalenceclasseswithoutanyknowledgeoftheprogramcodeis2,whereasthenumberofequivalenceclassesderivedwiththeknowledgeofpartialcodeis6.Ofcourse,anexperiencedtesterwilllikelyderivethesixequivalenceclassesgivenabove,andperhapsmore,evenbeforethecodeisavailableExample 2 (contd.)Insomecasestheequi
35、valenceclassesarebasedontheoutputgeneratedbytheprogram.Forexample,supposethataprogramoutputsaninteger.Itisworthasking:“Doestheprogramevergeneratea0?Whatarethemaximumandminimumpossiblevaluesoftheoutput?”Thesetwoquestionsleadtotwothefollowingequivalenceclassesbasedonoutputs:Equivalence classes based o
36、n program outputE1:Outputvaluevis0.E2:Outputvaluevisthemaximumpossible.E3:Outputvaluevistheminimumpossible.E4:Allotheroutputvalues.Basedontheoutputequivalenceclassesonemaynowderiveequivalenceclassesfortheinputs.Thuseachofthefourclassesgivenabovemightleadtooneequivalenceclassconsistingofinputs.Equiva
37、lence classes based on program output (contd.)Equivalence classes for variables: rangeEq.ClassesExampleOneclasswithvaluesinsidetherangeandtwowithvaluesoutsidetherange.speed60.9050,75,92area:floatarea0.0-1.0,15.52age:int-1,56,132letter:boolJ,3ConstraintsClassesEq.ClassesExampleAtleastonecontainingall
38、legalstringsandoneallillegalstringsbasedonanyconstraints.firstname:string,Sue,LoooongNameConstraintsClassesEquivalence classes for variables: stringsEq.ClassesExampleEachvalueinaseparateclassautocolor:red,blue,greenred,blue,greenup:booleantrue,falseConstraintsClassesEquivalence classes for variables
39、: enumerationEq.ClassesExampleOneclasscontainingalllegalarrays,onecontainingtheemptyarray,andonecontainingalargerthanexpectedarray.intaName:newint3;,-10,20,-9,0,12,15ConstraintsClassesEquivalence classes for variables: arraysArraysinJavaandrecords,orstructures,inC+,arecompoundtypes.Suchinputtypesmay
40、arisewhiletestingcomponentsofanapplicationsuchasafunctionoranobject.Whilegeneratingequivalenceclassesforsuchinputs,onemustconsiderlegalandillegalvaluesforeachcomponentofthestructure.Thenextexampleillustratesthederivationofequivalenceclassesforaninputvariablethathasacompoundtype.Equivalence classes f
41、or variables: compound data typestructtranscriptstringfName;/Firstname.stringlName;/Lastname.stringcTitle200;/Coursetitles.chargrades200;/Lettergradescorrespondingtocoursetitles.In-class exercise: Derive equivalence classes for each component of R and combine them!Equivalence classes for variables:
42、compound data type: ExampleOnewaytopartitiontheinputdomainistoconsideroneinputvariableatatime.Thuseachinputvariableleadstoapartitionoftheinputdomain.Werefertothisstyleofpartitioningasunidimensionalequivalencepartitioningorsimplyunidimensionalpartitioning.This type of partitioning is commonly used.Un
43、idimensional partitioningAnotherwayistoconsidertheinputdomainIasthesetproductoftheinputvariablesanddefinearelationonI.Thisprocedurecreatesonepartitionconsistingofseveralequivalenceclasses.Werefertothismethodasmultidimensionalequivalencepartitioningorsimplymultidimensionalpartitioning.Multidimensiona
44、lpartitioningleadstoalargenumberofequivalenceclassesthataredifficulttomanagemanually.Manyclassessocreatedmightbeinfeasible.Nevertheless,equivalenceclassessocreatedofferanincreasedvarietyoftestsasisillustratedinthenextsection.Multidimensional partitioningConsideranapplicationthatrequirestwointegerinp
45、utsxandy.Eachoftheseinputsisexpectedtolieinthefollowingranges:3x7and5y9.Forunidimensionalpartitioningweapplythepartitioningguidelinestoxandyindividually.Thisleadstothefollowingsixequivalenceclasses.Partitioning ExampleE1:x7y ignored.E4:y9x ignored.Formultidimensionalpartitioningweconsidertheinputdom
46、aintobethesetproductXxY.Thisleadsto9equivalenceclasses.Partitioning Example (contd.)E1:x3,y5E2:x3,5y9E3:x9E4:3x7,y9E7:7,y7,5y9E9:x7,y9Partitioning Example (contd.)6 equivalence classes:9 equivalence classes:E1:x3,y5E2:x3,5y9E3:x9E4:3x7,y9E7:7,y7,5y9E9:x7,y9Partitioning Example (contd.)1.Identifythei
47、nputdomain:Readtherequirementscarefullyandidentifyallinputandoutputvariables,theirtypes,andanyconditionsassociatedwiththeiruse.Environmentvariables,suchasclassvariablesusedinthemethodundertestandenvironmentvariablesinUnix,Windows,andotheroperatingsystems,alsoserveasinputvariables.Giventhesetofvalues
48、eachvariablecanassume,anapproximationtotheinputdomainistheproductofthesesets.Systematic procedure for equivalence partitioning2.Equivalenceclassing:Partitionthesetofvaluesofeachvariableintodisjointsubsets.Eachsubsetisanequivalenceclass.Together,theequivalenceclassesbasedonaninputvariablepartitionthe
49、inputdomain.partitioningtheinputdomainusingvaluesofonevariable,isdonebasedonthetheexpectedbehavioroftheprogram.Valuesforwhichtheprogramisexpectedtobehaveinthe“sameway”aregroupedtogether.Notethat“sameway”needstobedefinedbythetester.Systematic procedure for equivalence partitioning (contd.)Theequivale
50、nceclassesarecombinedusingthemultidimensionalpartitioningapproachdescribedearlier.3.Combineequivalenceclasses:Thisstepisusuallyomittedandtheequivalenceclassesdefinedforeachvariablearedirectlyusedtoselecttestcases.However,bynotcombiningtheequivalenceclasses,onemissestheopportunitytogenerateusefultest
51、s.Systematic procedure for equivalence partitioning (contd.)Forexample,supposethatanapplicationistestedviaitsGUI,i.e.dataisinputusingcommandsavailableintheGUI.TheGUImightdisallowinvalidinputsbyofferingapaletteofvalidinputsonly.Theremightalsobeconstraintsintherequirementsthatrendercertainequivalencei
52、nfeasible.4.Identifyinfeasibleequivalenceclasses:Aninfeasibleequivalenceclassisonethatcontainsacombinationofinputdatathatcannotbegeneratedduringtest.Suchanequivalenceclassmightariseduetoseveralreasons.Systematic procedure for equivalence partitioning (contd.)CommandtempcausesCStoasktheoperatortoente
53、rtheamountbywhichthetemperatureistobechanged(tempch).Valuesoftempchareintherange-10.10inincrementsof5degreesFahrenheit.Antemperaturechangeof0isnotanoption.ThecontrolsoftwareofBCS,abbreviatedasCS,isrequiredtoofferseveraloptions.Oneoftheoptions,C(forcontrol),isusedbyahumanoperatortogiveoneoffourcomman
54、ds(cmd):changetheboilertemperature(temp),shutdowntheboiler(shut),andcanceltherequest(cancel).Boiler control example (BCS)Thecommandfilemaycontainanyoneofthethreecommands,togetherwiththevalueofthetemperaturetobechangedifthecommandistemp.ThefilenameisobtainedfromvariableF.SelectionofoptionCforcestheBC
55、StoexaminevariableV.IfVissettoGUI,theoperatorisaskedtoenteroneofthethreecommandsviaaGUI.However,ifVissettofile,BCSobtainsthecommandfromacommandfile.BCS: example (contd.)Control Software(CS)GUIdatafilecmdtempchVFcmd: command (temp, shut, cancel)tempch: desired temperature change(-10.10)V, F: Environm
56、ent variablesV GUI, file F: file name if V is set to “file.”BCS: example (contd.)ValuesofVandFcanbealteredbyadifferentmoduleinBCS.Inresponsetotempandshutcommands,thecontrolsoftwareisrequiredtogenerateappropriatesignalstobesenttotheboilerheatingsystem.BCS: example (contd.)TheGUIforcesthetestertoselec
57、tfromalimitedsetofvaluesasspecifiedintherequirements.Forexample,theonlyoptionsavailableforthevalueoftempchare-10,-5,5,and10.Werefertothesefourvaluesoftempchastvalidwhileallothervaluesastinvalid.Weassumethatthecontrolsoftwareistobetestedinasimulatedenvironment.Thetestertakesontheroleofanoperatorandin
58、teractswiththeCSviaaGUI.BCS: example (contd.)Thefirststepingeneratingequivalencepartitionsistoidentifythe(approximate)inputdomain.Recallthatthedomainidentifiedinthisstepwilllikelybeasupersetofthecompleteinputdomainofthecontrolsoftware.Firstweexaminetherequirements,identifyinputvariables,theirtypes,a
59、ndvalues.Thesearelistedinthefollowingtable.BCS: 1. Identify input domainVariableKindTypeValue(s)VEnvironmentEnumeratedFile,GUIFEnvironmentStringAfilenamecmdInputviaGUI/FileEnumeratedtemp,cancel,shuttempchInputviaGUI/FileEnumerated-10,-5,5,10BCS: Variables, types, valuesInput domainS=VFcmdtempch Samp
60、le values in the input domain (-: dont care):(GUI, -, shut, -), (file, cmdfile, shut, -)(file, cmdfile, temp, 0)Does this belong to the input domain?BCS: Input domainVariablePartitionVGUI,file,undefinedFfvalid,finvalidcmdtemp,cancel,shut,cinvalidtempchtvalid,tinvalidBCS: 2. Equivalence classingThere
61、 is a total of 3425=120 equivalence classes.Note that tinvalid, tvalid, finvalid, and fvalid denote sets of values. “undefined” denotes one value.Sample equivalence class: (GUI, fvalid, temp, -10)Note that each of the classes listed above represents an infinite number of input values for the control
62、 software. For example, (GUI, fvalid, temp, -10) denotes an infinite set of values obtained by replacing fvalid by a string that corresponds to the name of an existing file. Each value is a potential input to the BCS.BCS: 3. Combine equivalence classes(V,F,cancel,shut,cinvalid,tvalidtinvalid)Notetha
63、ttheGUIrequestsfortheamountbywhichtheboilertemperatureistobechangedonlywhentheoperatorselectstempforcmd.Thusallequivalenceclassesthatmatchthefollowingtemplateareinfeasible.Thisparent-childrelationshipbetweencmdandtempchrendersinfeasibleatotalof3235=90equivalenceclasses.Exercise: How many additional
64、equivalence classes are infeasible? BCS: 4. Discard infeasible equivalence classesAfterhavingdiscardedallinfeasibleequivalenceclasses,weareleftwithatotalof18testable(orfeasible)equivalenceclasses.BCS: 4. Discard infeasible equivalence classes (contd.)Givenasetofequivalenceclassesthatformapartitionof
65、theinputdomain,itisrelativelystraightforwardtoselecttests.However,complicationscouldariseinthepresenceofinfeasibledataanddontcarevalues.Inthemostgeneralcase,atestersimplyselectsonetestthatservesasarepresentativeofeachequivalenceclass.Exercise: Generate sample tests for BCS from the remaining feasibl
66、e equivalence classes.Selecting test dataWhiledesigningequivalenceclassesforprogramsthatobtaininputexclusivelyfromakeyboard,onemustaccountforthepossibilityoferrorsindataentry.Forexample,therequirementforanapplication.TheapplicationplacesaconstraintonaninputvariableXsuchthatitcanassumeintegralvaluesi
67、ntherange0.4.However,testingmustaccountforthepossibilitythatausermayinadvertentlyenteravalueforXthatisoutofrange.GUI design and equivalence classesSupposethatalldataentrytotheapplicationisviaaGUIfrontend.SupposealsothattheGUIoffersexactlyfivecorrectchoicestotheuserforX.Insuchasituationitisimpossible
68、totesttheapplicationwithavalueofXthatisoutofrange.HenceonlythecorrectvaluesofXwillbeinput.Seefigureonthenextslide.GUI design and equivalence classes (contd.)GUI design and equivalence classes (contd.)BoundaryvalueanalysisExperienceindicatesthatprogrammersmakemistakesinprocessingvaluesatandnearthebou
69、ndariesofequivalenceclasses.Forexample,supposethatmethodMisrequiredtocomputeafunctionf1whenx0istrueandfunctionf2otherwise.However,Mhasanerrorduetowhichitcomputesf1forx0.Errors at the boundariesBoundaryvalueanalysisisatestselectiontechniquethattargetsfaultsinapplicationsattheboundariesofequivalencecl
70、asses.Whileequivalencepartitioningselectstestsfromwithinequivalenceclasses,boundaryvalueanalysisfocusesontestsatandneartheboundariesofequivalenceclasses.Certainly,testsderivedusingeitherofthetwotechniquesmayoverlap.Boundary value analysis (BVA)1Partitiontheinputdomainusingunidimensionalpartitioning.
71、Thisleadstoasmanypartitionsasthereareinputvariables.Alternately,asinglepartitionofaninputdomaincanbecreatedusingmultidimensionalpartitioning.Wewillgenerateseveralsub-domainsinthisstep.2Identifytheboundariesforeachpartition.Boundariesmayalsobeidentifiedusingspecialrelationshipsamongsttheinputs.3Selec
72、ttestdatasuchthateachboundaryvalueoccursinatleastonetestinput.BVA: ProcedureAssumingthatanitemcodemustbeintherange99.999andquantityintherange1.100,Equivalenceclassesforcode:E1:Valueslessthan99.E2:Valuesintherange.E3:Valuesgreaterthan999.Equivalenceclassesforqty:E4:Valueslessthan1.E5:Valuesintherange
73、.E6:Valuesgreaterthan100.BVA: Example: 1. Create equivalence classesEquivalence classes and boundaries for findPrice. Boundaries are indicated with an x. Points near the boundary are marked *.E1E2E398100998100099999xx*E4E5E602991011100xx*BVA: Example: 2. Identify boundariesTestselectionbasedonthebou
74、ndaryvalueanalysistechniquerequiresthattestsmustinclude,foreachvariable,valuesatandaroundtheboundary.Considerthefollowingtestset:T=t1:(code=98,qty=0),t2:(code=99,qty=1),t3:(code=100,qty=2),t4:(code=998,qty=99),t5:(code=999,qty=100),t6:(code=1000,qty=101)Illegal values of code and qty included.BVA: E
75、xample: 3. Construct test setIsTthebestpossibletestsetforfindPrice?AnswerthisquestionbasedonTsabilitytodetectmissingcodeforcheckingthevalidityofage.Isthereanadvantageofseparatingtheinvalidvaluesofcodeandageintodifferenttestcases?BVA: In-class exerciseRelationshipsamongsttheinputvariablesmustbeexamin
76、edcarefullywhileidentifyingboundariesalongtheinputdomain.Thisexaminationmayleadtoboundariesthatarenotevidentfromequivalenceclassesobtainedfromtheinputandoutputvariables.Additionaltestsmaybeobtainedwhenusingapartitionoftheinputdomainobtainedbytakingtheproductofequivalenceclassescreatedusingindividual
77、variables.BVA: RecommendationsDecisionTableBasedtesting87Decision Tables - Generaln Decisiontablesareapreciseyetcompactwaytomodelcomplicatedlogic.Decisiontables,likeif-then-elseandswitch-casestatements,associateconditionswithactionstoperform.nBut,unlikethecontrolstructuresfoundintraditionalprogrammi
78、nglanguages,decisiontablescanassociatemanyindependentconditionswithseveralactionsinanelegantway.88Decision Tables - UsagenDecisiontablesmakeiteasiertoobservethatallpossibleconditionsareaccountedfor.nDecisiontablescanbeusedfor:nSpecifyingcomplexprogramlogicnGeneratingtestcases(Alsoknownaslogic-based
79、testing)nLogic-based testing isconsideredas:nstructuraltestingwhenappliedtostructure(i.e.controlflowgraphofanimplementation).nfunctionaltestingwhenappliedtoaspecification. 89Decision Tables - StructureConditions-(Condition stub)ConditionAlternatives(Condition Entry)Actions(Action Stub)ActionEntries
80、Each condition corresponds to a variable, relation or predicate Possible values for conditions are listed among the condition alternatives Boolean values (True / False) Limited Entry Decision Tables Several values Extended Entry Decision Tables Dont care value Each action is a procedure or operation
81、 to perform The entries specify whether (or in what order) the action is to be performed 90nToexpresstheprogramlogicwecanusealimited-entrydecisiontableconsistingof4areascalledthecondition stub, condition entry, action stubandtheaction entry:Rule1Rule2Rule3Rule4Condition1YesYesNoNoCondition2YesXNoXCo
82、ndition3NoYesNoXCondition4NoYesNoYesAction1YesYesNoNoAction2NoNoYesNoAction3NoNoNoYesCondition stubAction stubAction EntryCondition entry91nWecanspecifydefault rulestoindicatetheactiontobetakenwhennoneoftheotherrulesapply.nWhenusingdecisiontablesasatesttool,defaultrulesandtheirassociatedpredicatesmu
83、stbeexplicitlyprovided.Rule5Rule6Rule7Rule8Condition1XNoYesYesCondition2XYesXNoCondition3YesXNoNoCondition4NoNoYesXDefault actionYesYesYesYes92Decision Table - ExampleConditionsPrinterdoesnotprintYYYYNNNNAredlightisflashingYYNNYYNNPrinterisunrecognizedYNYNYNYNActionsCheckthepowercableXChecktheprinte
84、r-computercableXXEnsureprintersoftwareisinstalledXXXXCheck/replaceinkXXXXCheckforpaperjamXXPrinter Troubleshooting93Decision Table Example94Decision Table Development Methodology1.Determineconditionsandvalues2.Determinemaximumnumberofrules3.Determineactions4.Encodepossiblerules5.Encodetheappropriate
85、actionsforeachrule6.Verifythepolicy7.Simplifytherules(reduceifpossiblethenumberofcolumns)95Decision Tables - UsagenTheuseofthedecision-tablemodelisapplicablewhen:nthespecificationisgivenorcanbeconvertedtoadecisiontable.ntheorderinwhichthepredicatesareevaluateddoesnotaffecttheinterpretationoftherules
86、orresultingaction.ntheorderofruleevaluationhasnoeffectonresultingaction.noncearuleissatisfiedandtheactionselected,nootherruleneedbeexamined.ntheorderofexecutingactionsinasatisfiedruleisofnoconsequence.nTherestrictionsdonotinrealityeliminatemanypotentialapplications.nInmostapplications,theorderinwhic
87、hthepredicatesareevaluatedisimmaterial.nSomespecificorderingmaybemoreefficientthansomeotherbutingeneraltheorderingisnotinherentintheprogramslogic.96Decision Tables - IssuesnBeforeusingthetables,ensure:nrulesmustbecompleteneverycombinationofpredicatetruthvaluesplusdefaultcasesareexplicitinthedecision
88、tablenrulesmustbeconsistentneverycombinationofpredicatetruthvaluesresultsinonlyoneactionorsetofactions97Test Case DesignnOncethespecificationhasbeenverified,theobjectiveistodemonstratethattheimplementationprovidesthecorrectactionforallcombinationsofpredicatevalues:niftherearekrulesovernbinarypredica
89、tes,thenthereareatleastkcasesandatmost2ncasestoconsider.nBasetestdesignonunexpandedrulesorontheexpandedruleswith2ntestsnfindtheinputvectortoforceeachcase.98Test Case DesignnToidentifytestcaseswithdecisiontables,weinterpretconditionsasinputs,andactionsasoutputs.nSometimesconditionsendupreferringtoequ
90、ivalenceclassesofinputs,andactionsrefertomajorfunctionalprocessingportionsoftheitembeingtested.nTherulesaretheninterpretedastestcases.The Triangle ProblemnFunctiontriangletakesthreeintegersa,b,cwhicharelengthoftrianglesides;calculateswhetherthetriangleisequilateral,isosceles,orscalene.nThetaskistowr
91、itedowntestcasesforthisfunctionn“Classical”testingtask(Myers)nDoitNOW!100Decision Table for the Triangle ProblemConditionsC1:ab+c?FTTTTTTTT TTC2:ba+c?-FTTTTTTT TTC3:ca+b?-FTTTTTT TTC4:a=b?-TTTTFF FFC5:a=c?-TTFFTT FFC6:b=c?-TFTFTF TFActionsA1:NotaTriangleXXXA2:ScaleneXA3:IsoscelesXX XA4:EquilateralXA
92、5:ImpossibleX XX101Test Cases for the Triangle ProblemCase IDabcExpected OutputDT1412NotaTriangleDT2142NotaTriangleDT3124NotaTriangleDT4555EquilateralDT5?ImpossibleDT6?ImpossibleDT7223IsoscelesDT8?ImpossibleDT9232IsoscelesDT10322IsoscelesDT11345Scalene102Decision Table for NextDate(First Attempt) nA
93、“date”consistsofthreeintegers:month,date,yearnNextDatetakesadateandreturnsthedateofthefollowingdaynLetusconsiderthefollowingequivalenceclasses:M1=month|monthhas30daysM2=month|monthhas31daysM3=month|monthisDecemberM4=month|monthisFebruaryD1=day|1day27D2=day|day=28D3=day|day=29D4=day|day=30D5=day|day=
94、31Y1=year|yearisaleapyearY2=year|yearisacommonyear103Decision Table for NextDate (1)Conditions 1 2 3 4 5 6 7 8 9 10C1:monthinM1M1M1M1M1M2M2M2M2M2C2:dayinD1D2D3D4D5D1D2D3D4D5C3:yearin-ActionsA1:ImpossibleXA2:IncrementdayXXXXXXXA3:ResetdayXXA4:IncrementmonthXXA5:resetmonthA6:Incrementyear104Decision T
95、able for NextDate (2)Conditions11 12 13 14 15 16 17 18 19 20 21 22C1:monthinM3M3M3M3M3M4M4M4M4M4M4M4C2:dayinD1D2D3D4D5D1D2D2D3D3D4D5C3:yearin-Y1Y2Y1Y2-ActionsA1:ImpossibleXXXA2:IncrementdayXXXXXXA3:ResetdayXXXA4:IncrementmonthXXA5:resetmonthXA6:IncrementyearX105Guidelines and ObservationsnDecisionTa
96、bletestingismostappropriateforprogramswherenthereisalotofdecisionmakingnthereareimportantlogicalrelationshipsamonginputvariablesnTherearecalculationsinvolvingsubsetsofinputvariablesnTherearecauseandeffectrelationshipsbetweeninputandoutputnThereiscomplexcomputationlogic(highcyclomaticcomplexity)nDeci
97、siontablesdonotscaleupverywellnDecisiontablescanbeiterativelyrefinedTestingpredicatesPredicatesarisefromrequirementsinavarietyofapplications.HereisanexamplefromParadkar,Tai,andVouk,“Specificationbasedtestingusingcause-effectgraphs,AnnalsofSoftwareEngineering,”V4,pp133-157,1997.Aboilerneedstobetobesh
98、utdownwhenthefollowingconditionshold:Where do predicates arise?1.ThewaterlevelintheboilerisbelowXlbs.(a)2.ThewaterlevelintheboilerisaboveYlbs.(b)3.Awaterpumphasfailed.(c)4.Apumpmonitorhasfailed.(d)5.Steammeterhasfailed.(e)The boiler is to be shut down when a or b is true or the boiler is in degraded
99、 mode and the steam meter fails. We combine these five conditions to form a compound condition (predicate) for boiler shutdown. Boiler in degraded mode when either is true.Boiler shutdown conditionsDenotingthefiveconditionsaboveasathroughe,weobtainthefollowingBooleanexpressionEthatwhentruemustforcea
100、boilershutdown:E=a+b+(c+d)ewherethe+signindicates“OR”andamultiplicationindicates“AND.”Thegoalofpredicate-basedtestgenerationistogeneratetestsfromapredicatepthatguaranteethedetectionofanyerrorthatbelongstoaclassoferrorsinthecodingofp.Boiler shutdown conditionsAconditionisrepresentedformallyasapredica
101、te,alsoknownasaBooleanexpression.Forexample,considertherequirementif the printer is ON and has paper then send document to printer.Thisstatementconsistsofaconditionpartandanactionpart.Thefollowingpredicaterepresentstheconditionpartofthestatement.pr:(printerstatus=ON)(printertray=empty)Another exampl
102、eWewillnowexaminetwotechniques,namedBORandBROforgeneratingteststhatareguaranteedtodetectcertainfaultsinthecodingofconditions.Theconditionsfromwhichtestsaregeneratedmightarisefromrequirementsormightbeembeddedintheprogramtobetested.Conditionsguardactions.Forexample,ifconditionthenactionIsatypicalforma
103、tofmanyfunctionalrequirements.Test generation from predicatesRelationaloperators(relop): ,=,.=and=areequivalent.Booleanoperators(bop):!,xoralsoknownasnot,AND,OR,XOR.Relationalexpression:e1relope2.(e.g.a+bc)e1ande2areexpressionswhosevaluescanbecomparedusingrelop.Simplepredicate:ABooleanvariableorarel
104、ationalexpression.(x65)PredicatesBooleanexpression:oneormoreBooleanvariablesjoinedbybop.(ab!c)a,b,andcarealsoknownasliterals.NegationisalsodenotedbyplacingabaroveraBooleanexpressionsuchasin(ab).Wealsowriteabforabanda+bforabwhenthereisnoconfusion.SingularBooleanexpression:Wheneachliteralappearsonlyon
105、ce,e.g.(ab!c)Boolean expressionsDisjunctivenormalform(DNF):Sumofproductterms:e.g.(pq)+(rs)+(ac).Conjunctivenormalform(CNF):Productofsums:e.g.:(p+q)(r+s)(a+c)Any Boolean expression in DNF can be converted to an equivalent CNF and vice versa.e.g.CNF: (p+!r)(p+s)(q+!r)(q+s) is equivalent to DNF: (pq+!r
106、s)Boolean expressions (contd.)Mutuallysingular:Booleanexpressionse1ande2aremutuallysingularwhentheydonotshareanyliteral.IfexpressionEcontainscomponentse1,e2,.theneiisconsideredsingularonlyifitissingularandmutuallysingularwiththeremainingelementsofE.Boolean expressions (contd.)Abstract syntax tree (A
107、ST) for: (a+b)c !p.Notice that internal nodes are labeled byBoolean and relational operatorsRoot node: OR-node is labeled as . (a+b)c!Leaf nodesRoot node (AND-node)pBoolean expressions: Syntax tree representationWhat faults are we targeting when testing for the correct implementation of predicates?B
108、ooleanoperatorfault:Supposethatthespecificationofasoftwaremodulerequiresthatanactionbeperformedwhenthecondition(ad)eistrue.Herea,b,c,anddareintegervariablesandeisaBooleanvariable.Fault model for predicate testing(ad)eIncorrectBooleanoperator(ad)eIncorrectnegationoperator(ad)eIncorrectBooleanoperator
109、s(ad)cIncorrectBooleanvariable.Correctpredicate:(ad)eBoolean operator faults(a=b)(cd)eIncorrectrelationaloperator(a=b)(cd)eTworelationaloperatorfaults(a=b)(cd)eIncorrectBooleanoperatorsCorrectpredicate:(ad)eRelational operator faultsEihasanoff-by-faultif|e3-e4|=foranytestcaseforwhiche1=e2.Correctpre
110、dicate:Ec:e1relop1e2.Incorrectpredicate:Ei:e3relop2e4.AssumethatEcandEiusethesamesetofvariables.Eihasanoff-by-*faultif|e3-e4|foranytestcaseforwhiche1=e2.Eihasanoff-by-+faultif|e3-e4|foranytestcaseforwhiche1=e2.Arithmetic expression faultsEi:ab.Givenc=1,Eihasanoff-by-1faultas|a-b|=1foratestcaseforwhi
111、cha=b+c,e.g.Correctpredicate:Ec:a(b+c).Assume=1.Ei:ab+1.Givenc=2,Eihasanoff-by-1*faultas|a-(b+1)|1foranytestcaseforwhicha=b+c;Ei:a0,Eihasanoff-by-1+faultas|a-(b-1)|1foranytestcaseforwhicha=b+c;.Arithmetic expression faults: ExamplesFindanincorrectversionofEcthathasoff-by-1fault.Giventhecorrectpredic
112、ate:Ec:2*X+Y2.Assume=1.FindanincorrectversionofEcthathasoff-by-1*fault.FindanincorrectversionofEcthathasoff-by-1+fault.Arithmetic expression faults: In class exerciseGivenacorrectpredicatepc,thegoalofpredicatetestingistogenerateatestsetTsuchthatthereisatleastonetestcasetTforwhichpcanditsfaultyversio
113、npi,evaluatetodifferenttruthvalues.Suchatestsetissaidtoguaranteethedetectionofanyfaultofthekindinthefaultmodelintroducedabove.Goal of predicate testingAsanexample,supposethatpc:ab+c.ConsideratestsetT=t1,t2wheret1:andt2:.Thefaultinpiisnotrevealedbyt1asbothpcandpievaluatetofalsewhenevaluatedagainstt1.
114、However,thefaultisrevealedbyt2aspcevaluatestotrueandpitofalsewhenevaluatedagainstt2.Goal of predicate testing (contd.)Correctpredicate:abExtraBooleanvariablefault:abcMissingBooleanvariablefault:aMissing or extra Boolean variable faultsConsiderthefollowingBoolean-RelationalsetofBR-symbols:BR=t,f,+,-F
115、orexample,considerthepredicateE:a”.AtestcasethatsatisfiesthisconstraintforEmustcauseEtoevaluatetofalse.ABRsymbolisaconstraintonaBooleanvariableorarelationalexpression.Predicate constraints: BR symbolsAconstraintCisconsideredinfeasibleforpredicateprifthereexistsnoinputvaluesforthevariablesinprthatsat
116、isfyc.Forexample,theconstrainttisinfeasibleforthepredicateabbdifitisknownthatda.Infeasible constraintsLetprdenoteapredicatewithn,n0,andoperators.ApredicateconstraintCforpredicateprisasequenceof(n+1)BRsymbols,oneforeachBooleanvariableorrelationalexpressioninpr.Whenclearfromcontext,wereferto“predicate
117、constraint”assimplyconstraint.TestcasetsatisfiesCforpredicatepr,ifeachcomponentofprsatisfiesthecorrespondingconstraintinCwhenevaluatedagainstt.ConstraintCforpredicateprguidesthedevelopmentofatestforpr,i.e.itoffershintsonwhatthevaluesofthevariablesshouldbeforprtosatisfyC.Predicate constraintspr(C)den
118、otesthevalueofpredicateprevaluatedusingatestcasethatsatisfiesC.Cisreferredtoasatrueconstraintwhenpr(C)istrueandafalseconstraintotherwise.AsetofconstraintsSispartitionedintosubsetsStandSf,respectively,suchthatforeachCinSt,pr(C)=true,andforanyCinSf,pr(C)=false.S=StSf.True and false constraintsConsider
119、thepredicatepr:b(r).ThefollowingtestcasesatisfiesCforpr.ThefollowingtestcasedoesnotsatisfyCforpr.Predicate constraints: ExampleWewilldiscussthreesuchcriterianamedBOR,BRO,andBRE.Givenapredicatepr,wewanttogenerateatestsetTsuchthatTisminimalandTguaranteesthedetectionofanyfaultintheimplementationofpr;fa
120、ultscorrespondtothefaultmodelwediscussedearlier.Predicate testing: criteriaAtestsetTthatsatisfiestheBORtestingcriterionforacompoundpredicatepr,guaranteesthedetectionofsingleormultipleBooleanoperatorfaultsintheimplementationofpr.TisreferredtoasaBOR-adequatetestsetandsometimeswrittenasTBOR.Predicate t
121、esting: BOR testing criterionAtestsetTthatsatisfiestheBROtestingcriterionforacompoundpredicatepr,guaranteesthedetectionofsingleormultipleBooleanoperatorandrelationaloperatorfaultsintheimplementationofpr.TisreferredtoasaBRO-adequatetestsetandsometimeswrittenasTBRO.Predicate testing: BRO testing crite
122、rionAtestsetTthatsatisfiestheBREtestingcriterionforacompoundpredicatepr,guaranteesthedetectionofsingleormultipleBooleanoperator,relationalexpression,andarithmeticexpressionfaultsintheimplementationofpr.TisreferredtoasaBRE-adequatetestsetandsometimeswrittenasTBRE.Predicate testing: BRE testing criter
123、ionLetTx,xBOR,BRO,BRE,beatestsetderivedfrompredicatepr.Letpfbeanotherpredicateobtainedfromprbyinjectingsingleormultiplefaultsofoneofthreekinds:Booleanoperatorfault,relationaloperatorfault,andarithmeticexpressionfault.TxissaidtoguaranteethedetectionoffaultsinpfifforsometTx,p(t)pf(t).Predicate testing
124、: guaranteeing fault detectionLetpr=adLetTBOR=t1,t2,t3isaBORadequatetestsetthatsatisfiesS.t1:;Satisfies(t,t),i.e.abistrueandcdisalsotrue.t2:;Satisfies(t,f)t3:;Satisfies(f,t)ConstraintsetS=(t,t),(t,f),(f,t)Guaranteeing fault detection: exampleGeneratesingleBooleanoperatorfaultsinpr:adandshowthatTguar
125、anteesthedetectionofeachfault.Guaranteeing fault detection: In class exerciseReviewofabasicdefinition:ThecrossproductoftwosetsAandBisdefinedas:AB=(a,b)|aAandbBTheontoproductoftwosetsAandBisdefinedas:AB=(u,v)|uA,vB,suchthateachelementofAappearsatleastonceasuandeachelementofBappearsonceasv.Note that A
126、Bisaminimalset.Algorithms for generating BOR, BRO, and BRE adequate testsLetA=t,=,andB=f,AB=(t,f),(t,),(=,f),(=,f),(,)AB=(t,f),(=,)AnyotherpossibilitiesforAB?Set products: ExampleAlgorithm for Generation of BOR constraint setAlgorithm for Generation of BOR constraint setAn illustration follows.Wewan
127、ttogenerateTBORfor:pr:adFirst,generatesyntaxtreeofpr.adGeneration of BOR constraint setWewillusethefollowingnotation:SN is the constraint set for node N in the syntax tree for pr. SNt is the true constraint set for node N in the syntax tree for pr.SNf is the false constraint set for node N in the sy
128、ntax tree for pr.SN= SNt SNf .Generation of the BOR constraint setSecond,labeleachleafnodewiththeconstraintset(t),(f).WelabelthenodesasN1, N2, and so on for convenience.NoticethatN1 and N2 are direct descendents of N3 which is an AND-node.adN1N2N3SN1= (t),(f)SN2= (t),(f)Generation of the BOR constra
129、int set (contd.)Third,computetheconstraintsetforthenexthighernodeinthesyntaxtree,inthiscaseN3.ForanANDnode,theformulaeusedarethefollowing.SN3t = SN1t SN2t =(t) (t)=(t,t)SN3f = (SN1f t2)(t1SN2f = (f) (t)(t)(f) = (f, t)(t, f) = (f, t),(t, f)(t),(f)ad(t),(f)N1N2N3SN3=(t,t), (f, t), (t, f)Generation of
130、the BOR constraint set (contd.)Asperourobjective,wehavecomputedtheBORconstraintsetfortherootnodeoftheAST(pr).WecannowgenerateatestsetusingtheBORconstraintsetassociatedwiththerootnode.SN3 contains a sequence of three constraints and hence we get a minimal test set consisting of three test cases. Here
131、 is one possible test set.TBOR =t1, t2, t3t1= (t, t)t2= (f, t)t3= (t, f)ad(t),(f)(t),(f)N1N2N3SN3=(t,t), (f, t), (t, f)Generation of TBORAlgorithm for Generation of BRO constraint setAlgorithm for Generation of BRO constraint set An illustration follows.RecallthatatestsetadequatewithrespecttoaBROcon
132、straintsetforpredicatepr,guaranteesthedetectionofallcombinationsofsingleormultipleBooleanoperatorandrelationaloperatorfaults.Algorithm for Generation of BRO constraint setTheBROconstraintsetSforrelationalexpressione1 relop e2:S=(),(=),(St=()Sf=(=),(),(=)Sf=()relop:=St=(=)Sf=()relop:St=()relop:St=()N
133、ote: tN denotes an element of StN. fN denotes an element of SfN BRO constraint setpr:(a+bs)Step1:ConstructtheASTforthegivenpredicate.prsa+bsa+b), (=), (), (=), ()(t), (f)BRO constraint set: Example (contd.)Step2:Traversethetreeandcomputeconstraintsetforeachinternalnode.StN4=SN1tSN3t=()(f)=(,=) (f) (
134、,f),(=,f) (,f),(=,f),(, t)BRO constraint set: Example (contd.)(,f),(=,f),(sa+b), (=), (), (=), (,f),(=,f),(,t) (=),(,f,=),(=,f,),(,t,=)StN6=(StN4 (fN5) (fN4) StN5)=(,f) ()=(,f,)=(,f,)BRO constraint set: Example (contd.)(,f,=),(=,f,),(,t,=),(,f,)(,f),(=,f),(sa+b), (=), (), (=), ()(t), (f)Constraint s
135、et forpr:(a+bs)BRO constraint set: Example (contd.)(,f,=),(=,f,),(,t,=),(,f,)Given the constraint set for pr:(a+bs),constructTBRO.BRO constraint set: In-class exerciseTest generation procedures described so far are for singular predicates. Recall that a singular predicate contains only one occurrenc
136、e of each variable. We will now learn how to generate BOR constraints for non-singular predicates.First, let us look at some non-singular expressions, their respective disjunctive normal forms (DNF), and their mutually singular components.BOR constraints for non-singular expressionsPredicate(pr)DNFM
137、utuallysingularcomponentsinprab(b+c)abb+abca;b(b+c)a(bc+bd)abc+abda;(bc+bd)a(!b+!c)+cde a!ba+a!c+cdea;!b+!c+cdea(bc+!b+de)abc+a!b+adea;bc+!b;deNon-singular expressions and DNF: ExamplesWe proceed in two steps. First we will examine the Meaning Impact (MI) procedure for generating a minimal set of co
138、nstraints from a possibly non-singular predicate. Next, we will examine the procedure to generate BOR constraint set for a non-singular predicate.Generating BOR constraints for non-singular expressionsGiven Boolean expression E in DNF, the MI procedure produces a set of constraints SE that guarantee
139、s the detection of missing or extra NOT (!) operator faults in the implementation of E.Meaning Impact (MI) procedureProcedure for generation a minimal constraint set from a Procedure for generation a minimal constraint set from a predicate possibly containing nonsingular expresspredicate possibly co
140、ntaining nonsingular expressnInput:ABooleanexpressionE=e1+e2+,eninminimaldisjunctivenormalformcontainingatermei,1incontainsli0literals.nOutput:AsetofconstraintsSEthatguaranteesthedetectionofmissingorextraNOToperatorfaultinafaultyversionofE.Step 1: For each term ei,1in, construct Tei as the set of co
141、nstraints that makes ei true. Step 2: From each Tei , remove the constraints that are in any other Tej. This gives us TSei and TSej. Note that this step will lead TSei TSej =.Procedure: MI-CSETStep 5: Let FSeji=Feji-n k=1Tek . Thus for any constraint cFSeji, p(c)=false.Step 6: Construct SfE that is
142、minimal and covers each FSeji at least once.Step 7: Construct the desired constraint set for E as SE= StE SfE. Step 4: let eij denote the term obtained by complementing the jth literal in term ei, for 1in, 1jlj.Wecounttheliteralsinatermfromlefttoright,theleftmostliteralbeingthefirst.ConstructFeijast
143、hesetofconstraintsthatmakeeijtrue.End of procedure MI-CSETStep 3: Construct StE by selecting one element from each TSe.Consider the non-singular predicate: a(bc+!bd). Its DNF equivalent is:E=abc+a!bd.Note that a, b, c, and d are Boolean variables and also referred to as literals. Each literal repres
144、ents a condition. For example, a could represent rs.Recall that + is the Boolean OR operator, ! is the Boolean NOT operator, and as per common convention we have omitted the Boolean AND operator. For example bc is the same as bc.MI procedure: An ExampleStep 0: Express E in DNF notation. Clearly, we
145、can write E=e1+e2, where e1=abc and e2=a!bd.Step 1: Construct a constraint set Te1 for e1 that makes e1 true. Similarly construct Te2 for e2 that makes e2 true. Note that the four ts in the first element of Te1 denote the values of the Boolean variables a, b,c, and d, respectively. The second elemen
146、t, and others, are to be interpreted similarly.Te1 =(t,t,t,t), (t,t,t,f)Te2 =(t,f,t,t), (t,f,f,t)MI procedure: An Example (contd.)Step 2: From each Tei , remove the constraints that are in any other Tej. This gives us TSei and TSej. Note that this step will lead TSei TSej =.There are no common const
147、raints between Te1 and Te2 in our example. Hence we get:TSe1 =(t,t,t,t), (t,t,t,f)TSe2 =(t,f,t,t), (t,f,f,t)MI procedure: Example (contd.)Step 3: Construct StE by selecting one element from each Te.StE =(t,t,t,t), (t,f,f,t)Note that for each constraint x in StE we get E(x)=true. Also, StE is minimal
148、. Check it out!MI procedure: Example (contd.)Step 4: For each term in E, obtain terms by complementing each literal, one at a time.e11= !abc e21= a!bc e31= ab!ce12= !a!bd e22= abd e32= a!b!dFrom each term e above, derive constraints Fe that make e true. We get the following six sets.MI procedure: Ex
149、ample (contd.)Fe11= (f,t,t,t), (f,t,t,f) Fe21= (t,f,t,t), (t,f,t,f) Fe31= (t,t,f,t), (t,t,f,f)Fe12= (f,f,t,t), (f,f,f,t) Fe22= (t,t,t,t), (t,t,f,t) Fe32= (t,f,t,f), (t,f,f,f)MI procedure: Example (contd.)FSe11= FSe11FSe21= (t,f,t,f) FSe31= FSe13FSe12= FSe12FSe22= (t,t,f,t) FSe32= FSe13Step 5: Now co
150、nstruct FSe by removing from Fe any constraint that appeared in any of the two sets Te constructed earlier.Constraints common with Te1 and Te2 are removed.MI procedure: Example (contd.)Step 6: Now construct SfE by selecting one constraint from each FeSfE =(f,t,t,f), (t,f,t,f), (t,t,f,t), (f,f,t,t) S
151、tep 7: Now construct SE= StE SfE SE=(t,t,t,t), (t,f,f,t), (f,t,t,f), (t,f,t,f), (t,t,f,t), (f,f,t,t) Note: Each constraint in StE makes E true and each constraint in SfE makes E false. Check it out! We are now done with the MI procedure.MI procedure: Example (contd.)The BOR-MI-CSET procedure takes a
152、 non-singular expression E as input and generates a constraint set that guarantees the detection of Boolean operator faults in the implementation of E.The BOR-MI-CSET procedure using the MI procedure described earlier. The entire procedure is described in the word document.BOR-MI-CSET procedureConsi
153、der a non-singular Boolean expression: E= a(bc+!bd)Mutually non-singular components of E: e1=a e2=bc+!bdWe use the BOR-CSET procedure to generate the constraint set for e1 (singular component) and MI-CSET procedure for e2 (non-singular component).BOR-MI-CSET: ExampleFor component e1 we get:Ste1=t. S
154、fe1=fRecall that Ste1 is true constraint set for e1 and Sfe1 is false constraint set for e1. BOR-MI-CSET: Example (contd.)Component e2 is a DNF expression. We can write e2=u+v where u=bc and v=!bd.Let us now apply the MI-CSET procedure to obtain the BOR constraint set for e2.As per Step 1 of the MI-
155、CSET procedure we obtain:Tu=(t,t,t), (t,t,f) Tv=(f,t,t), (f,f,t)BOR-MI-CSET: Example (contd.)Applying Steps 2 and 3 to Tu and Tv we obtain:TSu=Tu TSv=TvSte2=(t,t,f), (f, t, t)One possible alternative. Can you think of other alternatives?Next we apply Step 4 to u and v. We obtain the following comple
156、mented expressions from u and v:u1=!bc u2=b!cv1=bdv2=!b!dBOR-MI-CSET: Example (contd.)Continuing with Step 4 we obtain:Fu1=(f,t,t), (f,t,f) Fu2=(t,f,t), (t,f,f)Fv1=(t,t,t), (t,f,t) Fv2=(f,t,f), (f,f,f)Next we apply Step 5 to the F constraint sets to obtain:FSu1=(f,t,f) FSu2=(t,f,t), (t,f,f)FSv1=(t,f
157、,t) FSv2=(f,t,f), (f,f,f)BOR-MI-CSET: Example (contd.)Applying Step 6 to the FS sets leads to the followingSfe2=(f,t,f), (t,f,t)Combing the true and false constraint sets for e2 we get:Se2=(t,t,f), (f, t, t), (f,t,f), (t,f,t)BOR-MI-CSET: Example (contd.)Summary:Ste1=(t)Sfe1=(f)from BOR-CSET procedur
158、e.Ste2=(t,t,f), (f, t, t) Sfe2=(f,t,f), (t,f,t) from MI-CSET procedure.We now apply Step 2 of the BOR-CSET procedure to obtain the constraint set for the entire expression E.BOR-MI-CSET: Example (contd.)(t),(f)(t,t,f), (f, t, t), (f,t,f), (t,f,t)aApply MI-CSETbc!bdN1N2N3(t,t,t,f), (t,f,t,t), (f,t,t,
159、f),(t,f,t,f),(t,t,f,t)Obtained by applying Step 2 of BOR-CSET to an AND node.StN3=StN1 StN2SfN3=(SfN1 t2)(t1 SfN2)BOR-MI-CSET: Example (contd.)TestingStateTransitionDiagrams182OutlinenGeneratingStateTransitionDiagramsnState-TransitionTablesnCreatingTestCases183State-Transition Testing ExampleState-T
160、ransition Testing ExamplenState-Transitiondiagramsareanexcellenttooltocapturecertaintypesofsystemrequirementsandtodocumentinternalsystemdesign.nThesediagramsdocumenttheeventsthatcomeintoandareprocessedbyasystemaswellasthesystemsresponses.184Reservation System Example 1- Make a reservationnProvideinf
161、ormationincludingdepartureanddestinationcities,dates,andtimes.nAreservationagentusesthatinformationtomakeareservation.nAtthatpoint,theReservationisintheMadestate.Thesystemcreatesandstartsatimer.nIfthistimerexpiresbeforethereservationispaidfor,thereservationiscancelledbythesystem.185Reservation Syste
162、m ExamplegiveInfo,isaneventthatcomesintothesystemfromtheoutsideworld.Thecommandafterthe/denotesanactionofthesystem;inthiscasestartPayTimer.186Reservation System ExamplenWhenmoneyispaid,throughinitiationofthePayMoneyaction,thesystemgoesintothe“Paid”state.nEventsmayhaveparametersassociatedwiththem.For
163、example,Pay MoneymayindicateCash, Check, Debit Card,orCredit CardnWhentheticketisprinted,thesystemgoesintotheTicketedStatenUponboardingtheplane,thecustomergivestheboardingpassalongwiththeticket,whichsignalsthatthetickethasbeenUsed.nAnythingelseafterthisstate?187Reservation System ExamplenIftheReserv
164、ationisnotpaidontime,thePayTimerexpiresandtheReservationiscancelledfornon-payment.nAreservationmaybecomecancelledifthecustomerwishestodoso.nThiscanhappenpriortopaymentorafterpayment.nIfafterpayment,arefundneedstobegenerated.nIfthecustomerhadtheticketswithhim,arefundcannotbegivenunlesstheprintedticke
165、titselfisreturnedtotheagent.nThisintroducesonenewnotationalelementsquarebracketsthatcontainaconditionalthatcanbeevaluatedeitherTrueorFalse.nThisconditionalactsasaguardallowingthetransitiononlyiftheconditionistrue.188State Transition Diagram of the Reservation System189State-Transition Tables nState-
166、transitiontablesmaybeeasiertouseinacompleteandsystematicmanner.nState-transitiontablesconsistoffourcolumnsCurrentState,Event,Action,andNextState.nBuildthestate-transitiontableasfollowsForeachstateofthesystemForeachevent/triggerofthesystemFindthecorresponding(Action,NextState)ifanyDocument(state,even
167、t,action,nextstate)190191192193194State-Transition Tables (Cont.)nTheadvantageofastate-transitiontableisthatitlistsallpossiblestate-transitioncombinations,notjustthevalidones.nWhentestingcritical,high-risksystemssuchasavionicsormedicaldevices,testingeverystate-transitionpairmayberequired,includingth
168、osethatarenotvalid.nCreatingastate-transitiontableoftenunearthscombinationsthatwerenotidentified,documented,ordealtwithintherequirements.Itishighlybeneficialtodiscoverthesedefectsbeforecodingbegins.195State-Transition Tables (Cont.)nUsingastate-transitiontablecanhelpdetectdefectsinimplementationthat
169、enableinvalidpathsfromonestatetoanother.nThedisadvantageofsuchtablesisthattheybecomeverylargeveryquicklyasthenumberofstatesandeventsincreases.nInaddition,thetablesaregenerallysparse;thatis,mostofthecellsareempty.196Creating Test Cases1.Create a set of test cases such that all states are visited at l
170、east once under test.Thesetofthreetestcasesshownbelowmeetsthisrequirement.Generallythisisaweakleveloftestcoverage.197A set of test cases that visit each state 198Creating Test Cases (Cont.)2.Create a set of test cases such that all events are triggered at least once under test.Notethatthetestcasesth
171、atcovereacheventcanbethesameasthosethatcovereachstate.Again,thisisaweaklevelofcoverage.199A set of test cases that trigger all events at least onceA set of test cases that trigger all events at least once 200Creating Test Cases (Cont.)3. Create a set of test cases such that all paths are executed at
172、 least once under test.nWhilethislevelisthemostpreferredbecauseofitslevelofcoverage,itmaynotbefeasible.nIfthestate-transitiondiagramhasloops,thenthenumberofpossiblepathsmaybeinfinite.Forexample,givenasystemwithtwostates,AandB,whereAtransitionstoBandBtransitionstoA.Afewofthepossiblepathsare:nABnABAnA
173、BABABnABABABAn.nandsoonforever.2013. Create a set of test cases such that all paths are executed at least 3. Create a set of test cases such that all paths are executed at least once under test (Cont.)once under test (Cont.)nTestingofloopssuchasthiscanbeimportantiftheymayresultinaccumulatingcomputat
174、ionalerrorsorresourceloss(lockswithoutcorrespondingreleases,memoryleaks,etc.).202Creating Test Cases (Cont.)4. Create a set of test cases such that all transitions are exercised at least once under test. Thisleveloftestingprovidesagoodlevelofcoveragewithoutgeneratinglargenumbersoftests.Thislevelisge
175、nerallytheonerecommended.203A set of test cases that trigger all transitions at least onceA set of test cases that trigger all transitions at least once 2044. A set of test cases that trigger all transitions at least once 4. A set of test cases that trigger all transitions at least once (Cont.)(Cont
176、.)nTestcasescanalsobereaddirectlyfromthestate-transitiontable.Thegrayrowsinthefollowingtableshowallthevalidtransitions.205206207208Creating Test Cases (Cont.)nInaddition,dependingonthesystemrisk,youmaywanttocreatetestcasesforsomeoralloftheinvalidstate/eventpairstomakesurethesystemhasnotimplementedin
177、validpaths.nApplicability and LimitationsnState-Transitiondiagramsareexcellenttoolstocapturecertainsystemrequirements,namelythosethatdescribestatesandtheirassociatedtransitions.Thesediagramsthencanbeusedtodirectourtestingeffortsbyidentifyingthestates,events,andtransitionsthatshouldbetested.nState-Tr
178、ansitiondiagramsarenotapplicablewhenthesystemhasnostateordoesnotneedtorespondtoreal-timeeventsfromoutsideofthesystem.Anexampleisapayrollprogramthatreadsanemployeestimerecord,computespay,subtractsdeductions,savestherecord,printsapaycheck,andrepeatstheprocess.209Key PointsnState-Transitiondiagramsdire
179、ctourtestingeffortsbyidentifyingthestates,events,actions,andtransitionsthatshouldbetested.Together,thesedefinehowasysteminteractswiththeoutsideworld,theeventsitprocesses,andthevalidandinvalidorderoftheseevents.nAstate-transitiondiagramisnottheonlywaytodocumentsystembehaviour.Theymaybeeasiertocompreh
180、end,butstate-transitiontablesmaybeeasiertouseinacompleteandsystematicmanner.nThegenerallyrecommendedleveloftestingusingstate-transitiondiagramsistocreateasetoftestcasessuchthatalltransitionsareexercisedatleastonceundertest.nInhigh-risksystems,youmaywanttocreateevenmoretestcases,approachingallpathsif
181、possible.Equivalence partitioning and boundary value analysis are the most commonly used methods for test generation while doing functional testing.pGiven a function f to be tested in an application, one can apply these techniques to generate tests for f.SummaryMost requirements contain conditions u
182、nder which functions are to be executed. Predicate testing procedures covered are excellent means to generate tests to ensure that each condition is tested adequately.Summary (contd.)Usually one would combine equivalence partitioning, boundary value analysis, and predicate testing procedures to generate tests for a requirement of the following type:if condition then action 1, action 2, action n;Apply predicate testingApply eq. partitioning, BVA, and predicate testing if there are nested conditions.Summary (contd.)