Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Software Testing Chapter 6-4 Input Space Partition Testing Paul Ammann & Jeff Offutt

Similar presentations


Presentation on theme: "Introduction to Software Testing Chapter 6-4 Input Space Partition Testing Paul Ammann & Jeff Offutt"— Presentation transcript:

1 Introduction to Software Testing Chapter 6-4 Input Space Partition Testing Paul Ammann & Jeff Offutt http://www.cs.gmu.edu/~offutt/softwaretest/

2 In-Class Extended Example Ch 6.4 Form teams of two to three neighbors Hand out printouts of Iterator.html –http://docs.oracle.com/javase/7/docs/api/java/util/Iterator.htmlhttp://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html Close books We will go through the steps for designing an IDM for Iterator After each step, we will stop & discuss as a class Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt2

3 Task I: Determine Characteristics Step 1: Identify: Functional units Parameters Return types and return values Exceptional behavior Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt3 work …

4 Task I: Determine Characteristics Step 1: Identify: hasNext () – Returns true if more elements E next() – Returns next element –Exception: NoSuchElementException void remove () – Removes the most recent element returned by the iterator –Exception: Unsupported-OperationException –Exception: IllegalStateException State of the iterator –and, as we’ll discover, the state of the collection we are iterating over! Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt4

5 Task I: Determine Characteristics Step 2: Develop Characteristics Table A: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt5 MethodParamsReturnsValuesExceptionCh IDCharacter -istic Covered by hasNextstatebooleantrue, false nextstate E element generic E, null removestate work …

6 Task I: Determine Characteristics Step 2: Develop Characteristics Table A: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt6 MethodParamsReturnsValuesExceptionCh IDCharacter -istic Covered by hasNextstatebooleantrue, falseC1More values nextstate E element generic E, null removestate

7 Task I: Determine Characteristics Step 2: Develop Characteristics Table A: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt7 MethodParamsReturnsValuesExceptionCh IDCharacter -istic Covered by hasNextstatebooleantrue, falseC1More values nextstate E element generic E, null C2Returns non-null object removestate

8 Task I: Determine Characteristics Step 2: Develop Characteristics Table A: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt8 MethodParamsReturnsValuesExceptionCh IDCharacter -istic Covered by hasNextstatebooleantrue, falseC1More values nextstate E element generic E, null C2Returns non-null object NoSuchEle ment C1 removestate

9 Task I: Determine Characteristics Step 2: Develop Characteristics Table A: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt9 MethodParamsReturnsValuesExceptionCh IDCharacter -istic Covered by hasNextstatebooleantrue, falseC1More values nextstate E element generic E, null C2Returns non-null object NoSuchEle ment C1 removestate Unsupport ed C3remove() supported

10 Task I: Determine Characteristics Step 2: Develop Characteristics Table A: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt10 MethodParamsReturnsValuesExceptionCh IDCharacter -istic Covered by hasNextstatebooleantrue, falseC1More values nextstate E element generic E, null C2Returns non-null object NoSuchEle ment C1 removestate Unsupport ed C3remove() supported IllegalStateC4remove() constraint satisfied Done!

11 Task I: Determine Characteristics Step 4: Design a partitioning Table B: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt11 hasNextnextremovePartition (all are boolean) C1 C2 C3 C4 work …

12 Task I: Determine Characteristics Step 4: Design a partitioning Table B: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt12 hasNextnextremovePartition (all are boolean) C1XXX C2XX C3X C4X

13 Task I: Determine Characteristics Step 4: Design a partitioning Table B: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt13 hasNextnextremovePartition (all are boolean) C1XXX{true, false} C2XX{true, false} C3X{true, false} C4X{true, false} Done with task I!

14 Task II: Define Test Requirements Step 1: Choose coverage criterion Step 2: Choose base cases if needed Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt14 work …

15 Task II: Define Test Requirements Step 1: Base coverage criterion (BCC) Step 2: Happy path (all true) Step 3: Test requirements … Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt15

16 Task II: Define Test Requirements Step 3: Test requirements Table C: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt16 work … MethodCharacteristicsTest RequirementsInfeasible TRs hasNextC1 nextC1 C2 removeC1 C2 C3 C4

17 Task II: Define Test Requirements Step 3: Test requirements Table C: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt17 MethodCharacteristicsTest RequirementsInfeasible TRs hasNextC1{T, F} nextC1 C2{TT, FT, TF} removeC1 C2 C3 C4{TTTT, FTTT, TFTT, TTFT, TTTF}

18 Task II: Define Test Requirements Step 4: Infeasible test requirements Table C: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt18 MethodCharacteristicsTest RequirementsInfeasible TRs hasNextC1{T, F}none nextC1 C2{TT, FT, TF}FT removeC1 C2 C3 C4{TTTT, FTTT, TFTT, TTFT, TTTF} FTTT C1=F: has no values C2=T: returns non-null object

19 Task II: Define Test Requirements Step 5: Revised infeasible test requirements Table C: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt19 MethodCharacteristicsTest RequirementsInfeasible TRs Revised TRs# TRs hasNextC1{T, F}nonen/a2 nextC1 C2{TT, FT, TF}FTFT  FF3 removeC1 C2 C3 C4{TTTT, FTTT, TFTT, TTFT, TTTF} FTTTFTTT  FFTT5 Done with task II!

20 Task III: Automate Tests First, we need an implementation of Iterator –( Iterator is just an interface) –ArrayList implements Iterator Test fixture has two variables: –List of strings –Iterator for strings setUp() –Creates a list with two strings –Initializes an iterator Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt20

21 Task III: Automate Tests remove () adds another complication … Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt21 “The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.” This is a precondition! List list = new ArrayList (); list.add(“cat”); list.add(“dog”); Iterator itr = list.iterator(); String s = itr.next(); // s has the value “cat” list.add(“elephant”); // just changed Collection! s = itr.next(); // precondition violated! // return value undefined!

22 Task III: Automate Tests Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt22 A competent tester would stop there All specified behaviors have been tested! But subtypes of Iterator are free do define behavior for the precondition In fact, Java Collection classes use an exception to do exactly that: ConcurrentModificationException

23 Task I: Determine Characteristics Cycle back to add another exception—Table A revised: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt23 MethodParamsReturnsValuesExceptionCh IDCharacter -istic Covered by work …

24 Task I: Determine Characteristics Cycle back to add another exception—Table A revised: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt24 MethodParamsReturnsValuesExceptionCh IDCharacter -istic Covered by hasNextstatebooleantrue, falseC1More values Concurrent Modification C5 nextstate E element generic E, null C2Returns non- null NoSuchEleme nt C1 Concurrent Modification C5 removestate UnsupportedC3remove() supported IllegalStateC4remove() constraint satisfied Concurrent Modification C5Collection not modified

25 Task II: Define Test Requirements Cycle back to Step 5: Revised infeasible test requirements Table C revised: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt25 MethodCharacteristicsTest RequirementsInfeasible TRs Revised TRs# TRs work …

26 Task II: Define Test Requirements Cycle back to Step 5: Revised infeasible test requirements Table C revised: Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt26 MethodCharacteristicsTest RequirementsInfeasible TRs Revised TRs# TRs hasNextC1 C5{TT, FT, TF}nonen/a3 nextC1 C2 C5{TTT, FTT, TFT, TTF}FTT TTF FTT  FFT TTF  TFF 4 removeC1 C2 C3 C4 C5 {TTTTT, FTTTT, TFTTT, TTFTT, TTTFT, TTTTF} FTTTTFTTTT  FFTTT 6

27 Task III: Automate Tests Introduction to Software Testing, Edition 2 (Ch 6)© Ammann & Offutt27 All tests are on the book website: http://cs.gmu.edu/~offutt/softwaretest/edition2/java/IteratorTest.java Implementation of iterator() explains anomalies in tests: ArrayList source code


Download ppt "Introduction to Software Testing Chapter 6-4 Input Space Partition Testing Paul Ammann & Jeff Offutt"

Similar presentations


Ads by Google