Presentation is loading. Please wait.

Presentation is loading. Please wait.

Com1040 Systems Design and Testing Part II – Testing (Based on A.J. Cowling’s lecture notes) LN-Test3: Equivalence classes and boundary conditions Marian.

Similar presentations


Presentation on theme: "Com1040 Systems Design and Testing Part II – Testing (Based on A.J. Cowling’s lecture notes) LN-Test3: Equivalence classes and boundary conditions Marian."— Presentation transcript:

1 Com1040 Systems Design and Testing Part II – Testing (Based on A.J. Cowling’s lecture notes) LN-Test3: Equivalence classes and boundary conditions Marian Gheorghe ©University of SheffieldCom1040 - Testing

2 Equivalence partition Boundary conditions Examples Specification-based testing Summary

3 Equivalence classes and boundaries Entities (variables) of a program have certain ranges of values – data sets, given by their types Data set boundaries are either explicitly defined in the application or provided by the programming language constructs or the programming environment Let us consider an entity e and its range min..Max Observations min, Max may be (1) implicitly introduced (minimum and maximum entity value – integers, reals; or empty set for various collections etc) or (2) may have defined values (maybe within implicitly defined range) testing will identify equivalence classes and may add boundary conditions around min and Max test set depends on the input set and the program under test

4 This example requires to check whether a given value belongs to a set of integers (either consecutive values or indexed by an array index). The integers form a range between min, the minimum value and Max, the maximum The equivalence classes are: { min } { Max } values from the set, but different from min and Max values outside the range (within [-2 n-1..2 n-1 ], n digits rep) Around boundary; new tests: min + ind, Max – ind ; where ind provides the next or previous element Test set has 6 elements = 4 partitions + 2 new boundaries Building partitions and boundaries is not always obvious… Example – partition and boundaries

5 Triangle example revisited The program accepts three positive whole numbers as lengths of the sides of a triangle and classifies the triangle according to its shape, equilateral, isosceles, scalene or returns impossible when there is no triangle. int triangle(int a, int b, int c) { int mx, x, y; mx = a; x = b; y = c; if (mx < b) {x = mx; mx = b;} if (mx < c) {y = mx; mx = c;} if (mx >= x + y) {return 4; // impossible} if (a == b && b == c) {return 1; // equilateral} if (a == b || b == c || a == c) {return 2; // isosceles} return 3; // scalene } Find maximum Answer

6 Build a test set using partitions and boundary values for the white box testing approach The range of input vales: D = N  N  N, N is the set of positive integers; D  D ext =Z  Z  Z, Z stands for integers Partitions are: Eq={(a,b,c)| a,b,c  N;a==b&&b==c} Is={(a,b,c)| a,b,c  N;a==b||b==c||a==c, (a,b,c)  Eq} Sc={(a,b,c)| a,b,c  N;(a,b,c)  Eq  Is} Im={(a,b,c)| a,b,c  N;(a,b,c)  Eq  Is  Sc} Other values - a,b,c with negative values, including 0? Boundary values? The test set with 4 values: representatives of Eq - (3,3,3), Is - (30,40,30), Sc – (3,5,7), Im – (6,10,2) Note: more than one partition in the range of input values Triangle example - partitions

7 public class TriangleClass { public static int triangle(int a, int b, int c) //… your code } // other methods } public class TestTriangle { @Test public void Equilateral() { assertEquals(1, TriangleClass.triangle(3,3,3), 0); } // other tests … } Triangle unit testing

8 public class TriangleClass { public static int triangle(int a, int b, int c) //… your code } // other methods } public class TestTriangle { @Test public void Equilateral() { assertEquals(1, TriangleClass.triangle(3,3,3), 0); } // other tests … } What else? Triangle unit testing

9 public class TriangleClass { public static int triangle(int a, int b, int c) //… your code } // other methods } public class TestTriangle { @Test public void Equilateral() { assertEquals(1, TriangleClass.triangle(3,3,3), 0); } // other tests … } Do we need to test the part computing the maximum value? Triangle unit testing

10 Triangle example – specification based We aim to generate test sets based on this specification: The program accepts three positive whole numbers as lengths of the sides of a triangle and classifies the triangle according to its shape, equilateral, isosceles, scalene or returns impossible when there is no triangle. The partitions generated above, Eq, Is, Sc, Im are utilised – they cover just D

11 Triangle example – specification based (2) We aim to generate test sets based on this specification: The program accepts three positive whole numbers as lengths of the sides of a triangle and classifies the triangle according to its shape, equilateral, isosceles, scalene or returns impossible when there is no triangle. The partitions generated above, Eq, Is, Sc, Im are utilised – they cover just D Other partitions:?

12 Triangle example – specification based (2) We aim to generate test sets based on this specification: The program accepts three positive whole numbers as lengths of the sides of a triangle and classifies the triangle according to its shape, equilateral, isosceles, scalene or returns impossible when there is no triangle. The partitions generated above, Eq, Is, Sc, Im are utilised – they cover just D Other partitions: D ext - D (excluding boundaries of D - outside D) – negative values and combinations: 3 with a -, 3 with -,- and (-,-,-),

13 Triangle example – specification based (3) We aim to generate test sets based on this specification: The program accepts three positive whole numbers as lengths of the sides of a triangle and classifies the triangle according to its shape, equilateral, isosceles, scalene or returns impossible when there is no triangle. The partitions generated above, Eq, Is, Sc, Im are utilised – they cover just D Other partitions: D ext - D (excluding boundaries of D - outside D) – negative values and combinations: 3 with a -, 3 with -,- and (-,-,-), Boundary conditions?

14 Triangle example – specification based (3) We aim to generate test sets based on this specification: The program accepts three positive whole numbers as lengths of the sides of a triangle and classifies the triangle according to its shape, equilateral, isosceles, scalene or returns impossible when there is no triangle. The partitions generated above, Eq, Is, Sc, Im are utilised – they cover just D Other partitions: D ext - D (excluding boundaries of D - outside D) – negative values and combinations: 3 with a -, 3 with -,- and (-,-,-), Boundary conditions: 0’s as side lengths – 7 more Test set with 4+7+7 test cases… some more might be considered navigating around boundary values by adding  1 at each component of every test case involved in checking boundaries (6+8  3+8  3 more)

15 Chunks of input data (1)Input data may occur at different instances in time Example. Given two sets, A and B, of integer values between min and Max, we aim to check whether there is any relationship between A and B (equality – A=B; inclusion - A  B, A  B; non-empty intersection - A  B  ). If A and B contain values outside the range then return 0, otherwise 1; for each of the above relationships, return an answer between 2..5. For sets A and B containing elements from the above range, such that the non-empty intersection holds, we should get 15; for a relationship non listed, 1, should be produced.  considered valid set. Two stages: (1) check that A, B contain elements between min and Max ; (2) check the relationship between A and B. The testing guided by A, B within min..Max A, B not in min..Max A, B relationship

16 Test set: partitions and boundaries (1.1) A, B contain all elements from min.. Max: , set with one element and set with arbitrary number of elements; in the last two cases consider boundaries, min, Max  9 +8  2 (either min or Max ) +6 (both min, Max ) =31 cases (1.2) A, B contain elements outside of min.. Max: exercise (2.1) Relationships between A and B: for each of the (1.1) case consider all the defined relationships. But, they are not independent – some redundant and others not appropriate. So, we need a more refined analysis. Let us consider A=B: (1)  =  ; (2) one element set, including boundaries – 3 cases; (3) arbitrary sets including boundaries – 2 elements;  total of 6; similarly for other relationships. Consequently, we keep the (1.1) 31 cases only for no relationship. (2.2) is empty as it shows the diagram below A, B within min..Max A, B not in min..Max A, B relationship

17 Equivalence partitions and boundary conditions Both applied for implementation- and specification-based unit testing Some general rules can be identified, but optimisations are expected Conclusions


Download ppt "Com1040 Systems Design and Testing Part II – Testing (Based on A.J. Cowling’s lecture notes) LN-Test3: Equivalence classes and boundary conditions Marian."

Similar presentations


Ads by Google