CEN 5070 - Software V & V Unit Testing Concepts

Embed Size (px)

DESCRIPTION

CEN 5070 - Software V & V Unit Testing Concepts. Purpose. This module presents the basic concepts of black-box and white-box testing for unit testing. A systematic approach is shown for deriving functional, boundary and white-box test cases. - PowerPoint PPT Presentation

Text of CEN 5070 - Software V & V Unit Testing Concepts

  • CEN 5070 - Software V & V

    Unit Testing Concepts

    Unit Test Concepts

  • PurposeThis module presents the basic concepts of black-box and white-box testing for unit testing. A systematic approach is shown for deriving functional, boundary and white-box test cases." arbitrarily selected test set ... results in inefficient testing, leavingsome functions untested while performing redundant testing of others."Darlene Mackay, Quality Consultants Unlimited

    Unit Test Concepts

  • AgendaWhat Is Unit TestingBlack-Box TestingWhite-Box TestingPutting It All Together

    Unit Test Concepts

  • WHAT IS UNIT TESTING?Executing a software element to determine whether it meets its specificationExecuting a software element to discover defects or anomaliesInspecting software element code to discover defects or anomalies.

    Unit Test Concepts

  • WHAT IS A UNIT?Named software element Separately invokablePerforms single functionExamplesSubprogram or scriptField with validationDatabase stored procedureJava class method

    Unit Test Concepts

  • SPRAE: A Model for Testing PracticeSpecification -- basis for software testingPremeditation -- testing requires planning, forethought Repeatability -- process, results independent of testerAccountability -- testing artifacts maintainedEconomy in the use of human, time and computing resources

    Unit Test Concepts

  • A TESTING LIFECYCLEAnalysisDesign

    Unit Test Concepts

  • AgendaWhat is Unit TestingBlack-Box TestingWhite-Box TestingPutting It All Together

    Unit Test Concepts

  • BLACK-BOX TESTINGTesting based on the specification rather than the implementation. Specification defines the expected response(s) to stimuliStimuliResponse(s)

    Unit Test Concepts

  • BLACK-BOX TECHNIQUESFunctional testing -- tests the behavior of the software. Boundary testing -- tests behavior at the lower/upper bounds of input valuesRandom testing -- tests using randomly generated stimuli (load testing)Intuitive (ad hoc) testing -- error guessing

    Unit Test Concepts

  • FUNCTIONAL TEST DESIGN METHODOLOGYSpecificationIdentify behaviors Develop test casesWrite test script

    Unit Test Concepts

  • EXAMPLE A(1) SpecificationCompute pay for an hourly employee, given the number of hours worked and the hourly pay rate. Compute overtime at 1.5 times hourly rate for hours in excess of 40.

    Unit Test Concepts

  • EXAMPLE A(2) Identify BehaviorsCase 1: No overtime (Hours 40)Expect Pay = 40*Rate+1.5*Rate*(Hours - 40)

    Unit Test Concepts

  • EXAMPLE A(3) Create Test CasesCase 1: No overtime (Hours 40)Use Rate = 10, Hours = 50 Expect Pay = 40*Rate+1.5*Rate*(Hours - 40) = 550

    Unit Test Concepts

  • EXAMPLE A(4) Write Test Script

    Unit Test Concepts

  • A MORE COMPLEX EXAMPLE (B)Increased number of behaviorsUse of decision table to document behaviorsTest case generation from decision table

    Unit Test Concepts

  • EXAMPLE B(1) SpecificationCompute pay for employee, given the number of hours worked and the hourly pay rate. For hourly employees (rate < 30), compute overtime at 1.5 times hourly rate for hours in excess of 40. Salaried employees (rate >= 30) are paid for exactly 40 hours.

    Unit Test Concepts

  • EXAMPLE B(2) Identify BehaviorsCase 1: Hourly AND No overtime (Rate < 30) & (Hours 40)Expect Pay = 40*Rate+1.5*Rate*(Hours - 40)Case 3: Salaried (Rate >= 30) Expect Pay = 40 * Rate

    Unit Test Concepts

  • DECISION TABLEColumns defineBehaviors

    Unit Test Concepts

  • EXAMPLE B(3) Create Test CasesOne test case per column of decision tableCase 1: Hourly, No OvertimeCase 2: Hourly, OvertimeCase 3: Salaried, No Extra HoursCase 4: Salaried, Extra HoursOrder the test cases by column

    Unit Test Concepts

  • EXAMPLE B(4) Write Test Script

    Unit Test Concepts

  • RULES -- DECISION TABLES Use 'Y', 'N', '-' or space

    Unit Test Concepts

  • Your Turn -- Problem P1(1) SpecificationCompute the dosage of drug X for patient, given the patient's Age and Weight. For patients 12 and under, the dosage is 1 pill. For patients over 65, the dosage is 2 pills. For all other patients, the dosage is 2 pills plus an extra pill for each 50 pounds above 120. The drug can not be given to patients over 300 pounds or over the age of 80.

    Unit Test Concepts

  • Your Turn(2a) Identify BehaviorsCaseExpected Stimulus Description#Pills 123456

    Unit Test Concepts

  • Your Turn (2b) Decision Table c1: Age 65 |c3: Age > 80 |c4: Weight > 300 |c5: Weight > 120 |a1: Pills = 0 |a2: Pills = 1 |a3: Pills = 2 |a4: Pills = 2+(W-120)/50 |

    Unit Test Concepts

  • Your Turn(3) Create Test Cases Case 1 2 3 4 5 6 7 8 9Age ___ ___ ___ ___ ___ ___ ___ ___ ___ Weight ___ ___ ___ ___ ___ ___ ___ ___ ___Pills ___ ___ ___ ___ ___ ___ ___ ___ ___

    Unit Test Concepts

  • Your Turn(4) Write Test ScriptStepStimuliPills= Age7891012Weight11

    Unit Test Concepts

  • SCALING UP

    The heart of the approach is to use a decision table as a thinking tool. The most critical task in this process is to identify all the stimuli and responses. When there are many logical combinations of stimuli, the decision table can become large, indicating that the unit is probably too complex.

    Unit Test Concepts

  • IDENTIFYING BEHAVIORApproachesWork backwardsIdentify each responseIdentify conditions that provoke responseIdentify separate stimuliWork forwardIdentify each stimulusIdentify how stimulus influences what unit doesSpecify the responseTreat stimuli combinations

    Unit Test Concepts

  • IDENTIFYING STIMULIArguments passed upon invocationInteractive user inputsInternal, secondary dataglobal or class variablesExternal data (sources)file or database status variablesfile or database dataExceptions

    Unit Test Concepts

  • IT PAYS TO BE A GOOD STIMULUS DETECTIVE Failure to identify stimuli results in an incomplete, possibly misleading test caseThe search for stimuli exposesinterface assumptions -- a major source of integration problemsincomplete design of unitinadequate provision for exception handling

    Unit Test Concepts

  • IDENTIFYING RESPONSESArguments/Results passed back on exitInteractive user outputsInternal, secondary dataupdated global or class variablesExternal data (sinks)output file or database status variablesoutput file or database dataExceptions

    Unit Test Concepts

  • IT PAYS TO BE A GOOD RESPONSE DETECTIVE Failure to identify responses results in incomplete understanding of the software under testshallow test casesincomplete expected resultsincomplete test "success" verification -- certain effects not checkedTo test, one must know all the effects

    Unit Test Concepts

  • A SKETCHING TOOL Black-Box SchematicStimulus TypeResponse TypeSoftwareunderTestArgumentInputsGlobalsDatabaseExceptionArgumentOutputsGlobalsDatabaseException

    Unit Test Concepts

  • BEFORE CONTINUTING

    Much of the discussion so far involves how to identify what software does. We have introduced thinking tools for systematically capturing our findings. These thought processes and tools can be used anywhere in the lifecycle, e.g., in software design!One Stone for Two Birds!!

    Unit Test Concepts

  • BOUNDARY TESTING DESIGN METHODOLOGYSpecificationIdentify elementary boundary conditions Identify boundary pointsGenerate boundary test casesUpdate test script (add boundary cases).

    Unit Test Concepts

  • (1) SpecificationCompute pay for an hourly employee, given the number of hours worked and the hourly pay rate. Compute overtime at 1.5 times hourly rate for hours in excess of 40.HoursPayRate

    Unit Test Concepts

  • (2) Identify Boundary ConditionsCondition 1 (bc1): Hours
  • (3) Identify Boundary Pointsbc1 (Hrs
  • (3a) BP Generalization bc x > y has TWO boundary pointsbp1: Just INside: x = y + precisionbp2: Just OUTside: x = ybc x = y has THREE boundary points:bp1: OUTlo: x = y - precisionbp2: OUThi: x = y + precisionbp3: AT: x = y

    Unit Test Concepts

  • (3b) BP Generalization bc x != y has THREE boundary points:bp1: INlo: x = y - precisionbp2: INhi: x = y + precisionbp3: OUT: x = y

    Unit Test Concepts

  • (4) Generate Test CasesCombine Hours boundary points with RateCase 1 (AT): Hours = 40, Rate = 10, Pay=400Case 2 (IN): Hours = 39, Rate = 10, Pay=390Case 3: (OUT): Hours = 41, Rate=10, Pay=415Observations:Test each boundary point individuallyThen consider pair-wise boundary points

    Unit Test Concepts

  • (5) Update Test ScriptStepStimuliExpected Response HoursRatePay =1230501010300550340104004391039054110415

    Unit Test Concepts

  • Your TurnBoundary Testing Decision Table:

    Unit Test Concepts

  • Your Turn (2-3) Boundary Conditions/PointsBoundary ConditionBoundary Point (BP)ATINbc1:OUTbc2:bc3:bc4:bc5:

    Unit Test Concepts

  • Your Turn(4) Generate Boundary Test CasesTo create a test case, you must pair an Age with a WeightWeight boundary point + NOMINAL AgeAge boundary point + NOMINAL WeightOUT Age + OUT Weight A nominal value is one that is not close to a boundary point. For simplicity, use the same nominal value in all test cases.

    Unit Test Concepts

  • Your Turn(4) Boundary-Nominal Test CasesCondition btc BC Weight Age Expect Weight>300 1 IN 301 21 0 2