Boundary Value Analysis
Boundary Value Analysis
Contents
1.0 Introduction 2.0 The Testing Problem 3.0 The Typing of Languages 4.0 Focus of BVA 5.0 Applying Boundary Value Analysis 5.1 Some Important examples 5.2 Critical Fault Assumption 5.3 Generalising BVA 5.4 Limitations of BVA 6.0 Robustness Testing 7.0 Worst Case Testing 7.1Robust Worst Case Testing 8.0 Examples: Test Cases 8.1 Next Date problem 8.2 Tri-angle problem 9.0 Conclusion 10.0 References 3 3 3 4 5 6 7 7 8 8 9 10 12 12 13 14 15
1.0 Introduction
The practice of testing software has become one of the most important aspects of the process of software creation. When we are testing software the first and potentially most crucial step is to design test cases. There are many methods associated with test case design. This report will document the approach known as Boundary Value analysis (BVA). As the incredibly influential Dijkstra stated Testing can show the presence of bugs, but not the absence. Although this is true we find that testing can be very good at the first, if implemented correctly. For this reason we need to know of the techniques available so we can find the correct method for the system under test (SUT). We will look at the various topics associated with Boundary Value Analysis and use some simple examples to show their meaning and purpose. There will be some examples to show the usefulness of each method. There will be an ongoing small scale example to help picture each method. This will be accompanied by two examples introduced by P.C. Jorgensen [1]. These will be used to show some more true to life requirements for testing techniques. There will be a chapter detailing test cases for these two more indepth examples.
ineffective when used in conjunction with languages of this nature, BVA can be seen as unsuitable for systems created using them. Boundary Value Analysis is therefore more suitable to more free-form languages such as COBOL and FORTRAN which are not so strongly typed. These are also known as weak typing languages and can be seen as languages which allow one type (i.e. a String) to be seen as another (i.e. an Int). This can be useful but it can also cause bugs. These bugs or errors are normally found in the ranges that BVA operates in and therefore can find.
x2
c a
Figure 4.1
x1
The Yellow shaded area of the graph shows the acceptable/legitimate input domain of the given function. As the name suggests Boundary Value Analysis focuses on the boundary of the input space to recognize test cases. The idea and motivation behind BVA is that errors tend to occur near the extremities of the input variables. The defects found on the boundaries of these input variables can obviously be the result of countless possibilities.
But there are many common faults that result in errors more collated towards the boundaries of input variables. For example if the programmer forgot to count from zero or they just miscalculated. Errors in the code concerning loop counters being off by one or the use of a < operator instead of . These are all very common mistakes and accompanied with other common errors we find an increasing need to perform Boundary Value Analysis.
In continuing our example this results in the following test cases shown in figures 5.1 and 5.2:
Figure 5.1
x2
d
Figure 5.2
c a b x1
You maybe wondering why it is we are only concerned with one of the values taking on their extreme values at any one particular time. The reason for this is that generally Boundary Value Analysis uses the Critical Fault Assumption. There are advantages and shortcomings of this method. The advantages will be discussed in chapter 5.2, and alternative methods will be shown in chapter 7.
5.1 Some Important examples To be able to demonstrate or explain the need for certain methods and their relative merits I will introduce two testing examples proposed by P.C. Jorgensen [1]. These examples will provide more extensive ranges to show where certain testing techniques are required and provide a better overview of the methods usability. The NextDate problem
The NextDate problem is a function of three variables: day, month and year. Upon the input of a certain date it returns the date of the day after that of the input. The input variables have the obvious conditions: 1 Day 31. 1 month 12. 1812 Year 2012. (Here the year has been restricted so that test cases are not too large). There are more complicated issues to consider due to the dependencies between variables. For example there is never a 31st of April no matter what year we are in. The nature of these dependencies is the reason this example is so useful to us. All errors in the NextDate problem are denoted by Invalid Input Date. The Triangle problem
In fact the first introduction of the Triangle problem is in 1973, Gruenburger. There have been many more references to this problem since making this one of the most popular example to be used in conjunction with testing literature. The triangle problem accepts three integers (a, b and c)as its input, each of which are taken to be sides of a triangle. The values of these inputs are used to determine the type of the triangle (Equilateral, Isosceles, Scalene or not a triangle). For the inputs to be declared as being a triangle they must satisfy the six conditions: C1. 1 a 200. C2. 1 b 200. C3. 1 c 200.
C4. a < b + c. C5. b < a + c. C6. c < a + b. Otherwise this is declared not to be a triangle. The type of the triangle, provided the conditions are met, is determined as follows: 1. If all three sides are equal, the output is Equilateral. 2. If exactly one pair of sides is equal, the output is Isosceles. 3. If no pair of sides is equal, the output is Scalene.
5.2 Critical Fault Assumption The Critical Fault Assumption also known as the single fault assumption in reliability theory. The assumption relies on the statistic that failures are only rarely the product of two or more simultaneous faults. Upon using this assumption we can reduce the required calculations dramatically. The amount of test cases for our example as you can recall was 9. Upon inspection we find that the function f that computes the number of test cases for a given number of variables n can be shown as: f = 4n + 1 As there are four extreme values this accounts for the 4n. The addition of the constant one constitutes for the instance where all variables assume their nominal value.
5.3 Generalising BVA There are two approaches to generalising Boundary Value Analysis. We can do this by the number of variables or by the ranges these variables use. To generalise by the number of variables is relatively simple. This is the approach taken as shown by the general Boundary Value Analysis technique using the critical fault assumption. Generalizing by ranges depends on the type of the variables. For example in the NextDate example proposed by P.C. Jorgensen [1], we have variable for the year, month and day. Languages similar to the likes of FORTRAN would normally encode the months variable so that January corresponded to 1 and February corresponded to 2 etc. Also it would be possible in some languages to declare an enumerated type {Jan, Feb, Mar,, Dec}. Either way this type of declaration is relatively simple because the ranges have set values. When we do not have explicit bounds on these variable ranges then we have to create our own. These are know as artificial bounds and can be illustrated via the use of the Tri-
angle problem. The point raised by P.C. Jorgensen was that we can easily impose a lower bound on the length of an edge for the tri-angle as an edge with a negative length would be silly. The problem occurs when trying to decide upon an upper bound for the length of each length. We could use a certain set integer, we could allow the program to use the highest possible integer (normally denoted as something to the effect of MaxInt). The arbitrary nature of this problem can lead to messy results or non concise test cases.
5.4 Limitations of BVA Boundary Value Analysis works well when the Program Under Test (PUT) is a function of several independent variables that represent bounded physical quantities [1]. When these conditions are met BVA works well but when they are not we can find deficiencies in the results. For example the NextDate problem, where Boundary Value Analysis would place an even testing regime equally over the range, testers intuition and common sense shows that we require more emphasis towards the end of February or on leap years. The reason for this poor performance is that BVA cannot compensate or take into consideration the nature of a function or the dependencies between its variables. This lack of intuition or understanding for the variable nature means that BVA can be seen as quite rudimentary.
Robustness testing ensues a sway in interest, where the previous interest lied in the input to the program, the main focus of attention associated with Robustness testing comes in the expected outputs when and input variable has exceeded the given input domain. For example the NextDate problem when we an entry like the 31st June we would expect an error message to the effect of that date does not exist; please try again. Robustness testing has the desirable property that it forces attention on exception handling. Although Robustness testing can be somewhat awkward in strongly typed languages it can show up altercations. In Pascal if a value is defined to reside in a certain range then and values that falls outside that range result in the run time errors that would terminate any normal execution. For this reason exception handling mandates Robustness testing.
x2 Robustness Test Cases (function of two variables)
d
Figure 6.1
c a b x1
Figure 6.2
We can see from the results in figures 7.1 and 7.2 that worst case testing is a more comprehensive testing technique. This can be shown by the fact that standard Boundary Value Analysis test cases are a proper subset of Worst-Case test cases.
x2
c a
Figure 7.1
x1
Figure 7.2
These test cases although more comprehensive in their coverage, constitute much more endeavour. To compare we can see that Boundary Value Analysis results in 4n + 1 test case where Worst-Case testing results in 5n test cases. As each variable has to assume each of its variables for each permutation (the Cartesian product) we have 5 to the n test cases. For this reason Worst-Case testing is generally used for situations that require a higher degree of testing (where failure of the program would be very costly)with less regard for the time and effort required as for many situations this can be too expensive to justify.
7.1 Robust Worst-Case Testing If the function under test were to be of the greatest importance we could use a method named Robust Worst-Case testing which as the name suggests draws it attributes from Robust and Worst-Case testing. Test cases are constructed by taking the Cartesian product of the 7-tuple set defined in the Robustness testing chapter. Obviously this results in the largest set of test results we have seen so far and requires the most effort to produce.
10
We can see that the function f (to calculate the number of test cases required) can be adapted to calculate the amount of Robust Worst-Case test cases. As there are now 7 values each variable can assume we find the function f to be: f = 7n This function has also been reached in the paper A Testing and analysis tool for Certain 3-Variable functions [2]. The results for the continuing example can be seen in figures 7.3 and 7.4.
Figure 7.3
Figure 7.4
11
For each example I will show test cases for the standard Boundary Value Analysis and the Worst-case testing techniques. These will show how the test cases are performed and how comprehensive the results are. There will not be test cases for Robustness testing or robust Worst-case testing as the cases covered should explain how the process works. Too many test cases would prove to be monotonous when trying to explain a concept, however when presenting a real project when the figures are more necessary all test cases should be detailed and explained to their full extent.
8.1 Next Date problem Standard Boundary Value Analysis test cases:
year min = 1812 min+ = 1813 nom = 1912 max- = 2011 max = 2012
12
As we can see there are only 60 of 125 test cases in this example, this shows the vast amount of test cases produced.
13
9.0 Conclusion
As Glenford J. Myers [3] summarises, we can find that Boundary Value Analysis if practised correctly, is one of the most useful test-case-design methods. But he goes on to say that it is often used ineffectively as the testers often see it as so simple they misuse it, or dont use it to its full potential. This is a very true interpretation of the use of Boundary Value Analysis. BVA can provide a relatively simple and formal testing technique that can be very powerful when used correctly. When issues arise such as dependencies between variables or a need for foresight into the systems functionality, we can find Boundary Value Analysis restrictive (as shown by the NextDate problem).
14
The underlying fact is that generally Boundary Value Testing techniques are computationally and theoretically inexpensive in the creation of test cases. For this reason in many cases it can be desirable in its results to effort ratio. This means that Boundary Value Analysis still has a part to play in modern day testing practises and should be wit us for some time to come.
10.0 References
[1] [2] [3] P. Jorgenson, Software Testing- A Craftsmans Approach, CRC Press, New York, 1995 Naryan C Debnath, Mark Burgin, Haesun K. Lee, Eric Thiemann, A Testing and analysis tool for Certain 3-Variable functions, Winona State University. Glenford J. Myers, The Art of Software Testing, John Wiley and Sons, Inc. 2004
15