Download Input Space Partitioning in Software Testing: Modeling the Input Domain with ISP and more Summaries Software Engineering in PDF only on Docsity!
Introduction to Software
Testing
Chapter 6
Input Space Partition Testing
Paul Ammann & Jeff Offutt
http://www.cs.gmu.edu/~offutt/softwaretest/
Modeling the Input Domain
- Step 1 : Identify testable functions
- Individual methods have one testable function
- Methods in a class often have the same characteristics
- Programs have more complicated characteristics—
modeling documents such as UML can be used to design
characteristics
- Systems of integrated hardware and software components
can use devices, operating systems, hardware platforms,
browsers, etc.
public enum Triangle { Scalene, Isosceles, Equilateral,
Invalid }
public static Triangle triang (int Side, int Side2, int Side3)
// Side1, Side2, and Side3 represent the lengths of the sides of
a triangle
// Returns the appropriate enum value
Modeling the Input Domain ( cont )
• Step 3 : Model the input domain
- The domain is scoped by the parameters
- The structure is defined in terms of characteristics
- Each characteristic is partitioned into sets of blocks
- Each block represents a set of values
- This is the most creative design step in using ISP
• Step 4 : Apply a test criterion to choose combinations of
values
- A test input has a value for each parameter
- One block for each characteristic
- Choosing all combinations is usually infeasible
- Coverage criteria allow subsets to be chosen
• Step 5 : Refine combinations of blocks into test inputs
- Choose appropriate values from each block
Two Approaches to Input Domain
Modeling
1. Interface-based approach
- Develops characteristics directly from individual input parameters
- Simplest application
- Can be partially automated in some situations
2. Functionality-based approach
- Develops characteristics from a behavioral view of the program under test
- Harder to develop—requires more design effort
- May result in better tests, or fewer tests that are as effective Input Domain Model (IDM)
1. Interface-Based Example
• Consider method triang() from class TriangleType on the
book website :
- http://www.cs.gmu.edu/~offutt/softwaretest/java/Triangle.java
- http://www.cs.gmu.edu/~offutt/softwaretest/java/TriangleType.java Introduction to Software Testing, Edition 2 (Ch 6) © Ammann & Offutt 7 public enum Triangle { Scalene, Isosceles, Equilateral, Invalid } public static Triangle triang (int Side, int Side2, int Side3) // Side1, Side2, and Side3 represent the lengths of the sides of a triangle // Returns the appropriate enum value The IDM for each parameter is identical Reasonable characteristic : Relation of side with zero
Interface-Based – triang()
• triang () has one testable function and three integer inputs
Introduction to Software Testing, Edition 2 (Ch 6) © Ammann & Offutt 12 Characteristic b 1 b 2 b 3 q 1 = “Relation of Side 1 to 0” greater than 0 equal to 0 less than 0 q 2 = “Relation of Side 2 to 0” greater than 0 equal to 0 less than 0 q 3 = “Relation of Side 3 to 0” greater than 0 equal to 0 less than 0 First Characterization of TriTyp’s Inputs
- Consider the characteristic q1 for side 1.
- If one value is chosen from each block, we will have three
tests:
- Test 1 (side 1 = 7, to satisfy block b1)
- Test 2 (side 1 = 0, to satisfy block b2)
- Test 3 (side 1 = - 2, to satisfy block b3)
Interface-Based IDM— triang ()
Second Characterization of triang()’s Inputs Characteristic b 1 b 2 b 3 b 4 q 1 = “Refinement of q 1 ” greater than 1 equal to 1 equal to 0 less than 0 q 2 = “Refinement of q 2 ” greater than 1 equal to 1 equal to 0 less than 0 q 3 = “Refinement of q 3 ” greater than 1 equal to 1 equal to 0 less than 0
• A maximum of 444 = 64 tests
• Complete because the inputs are integers (0.. 1)
Possible values for partition q 1 Characteristic b 1 b 2 b 3 b 4 Side1 (^5) 2 (^) (^1 0) - - 1 5 Test boundary conditions
2. Functionality-Based Approach
• Identify characteristics that correspond to the intended
functionality
• Requires more design effort from tester
• Can incorporate domain and semantic knowledge
• Can use relationships among parameters
• Modeling can be based on requirements, not
implementation
• The same parameter may appear in multiple
characteristics, so it’s harder to translate values to test
cases
Functionality-Based IDM —triang ()
• Values for this partitioning can be chosen as
Possible values for geometric partition q
1 Characteristic b 1 b 2 b 3 b 4 Triangle (4, 5, 6) (3, 3, 4) (3, 3, 3) (3, 4, 8)
Functionality-Based IDM— triang ()
• A different approach would be to break the geometric
characterization into four separate characteristics
Four Characteristics for triang () Characteristic b 1 b 2 q 1 = “Scalene” True False q 2 = “Isosceles” True False q 3 = “Equilateral” True False q 4 = “Valid” True False
- Use constraints to ensure that
- Equilateral = True implies Isosceles = True
- Valid = False implies Scalene = Isosceles = Equilateral = False
In-Class Exercise
Introduction to Software Testing, Edition 2 (Ch 6) © Ammann & Offutt 20
Work with 2 or 3 classmates
Create two IDMs for findElement () :
1) Interface-based
2) Functionality-based
public boolean findElement (List list, Object element) // Effects: if list or element is null throw NullPointerException // else return true if element is in the list, false otherwise
Steps 1 & 2—Interface & Functionality-Based public boolean findElement (List list, Object element) // Effects: if list or element is null throw NullPointerException // else return true if element is in the list, false otherwise Interface-Based Approach Two parameters : list, element Characteristics : list is null (block1 = true, block2 = false) list is empty (block1 = true, block2 = false) Functionality-Based Approach Two parameters : list, element Characteristics : number of occurrences of element in list (0, 1, >1) element occurs first in list (true, false) element occurs last in list (true, false)
Required Reading
• Chapter 6 from Amman’s and Offut’s book: An
Introduction to Software Testing
Introduction to Software Testing, Edition 2 (Ch 6) © Ammann & Offutt 23