Software Testing: Boundary Value Analysis using Boundary Value Checking

Swati Rajwal
Geek Culture
Published in
4 min readJun 9, 2021

--

Boundary Value Analysis (BVA) is a technique employed for black-box testing (also called Dynamic Testing). As a software tester, you always want to maximize the probability of finding errors. The test cases designed with boundary input values have high chances to find errors. This is how BVA can be a good choice to test software.

Problem Statement

Let us consider the triangle problem. According to this, the software program should accept three sides of a triangle. The program then identifies if the triangle is equilateral, Isosceles, Scalene, or Not a Triangle. We can assume the three sides to be X, Y, and Z. Each side can have a value between the range of [1,10].

Boundary Value Analysis (BVA)

It is a technique to cover the boundary values of given inputs in the test cases so as to find potential bugs. In our example, boundary checking can be done at 1 and 10 respectively. It will be clear as we proceed further. There are many ways to design the test cases using the BVA approach:

  1. Boundary Value Checking (BVC)
  2. Robustness Testing Method
  3. Worst Case Testing Method

For the sake of simplicity, we are going to consider BVA using boundary value checking (BVC). For the other two methods, we will create separate tutorials.

Conditions

As the three input values can lie in the range of [1,10], the following conditions are possible.

Generating the Test Cases

According to BVA-BVC, the total number of test cases for ’n’ input values is (4n+1). Hence for our example number of test cases will be (4*3 + 1), i.e., 13.

As the very first steps in BVC, you should define the maximum and minimum values for the given input values range.

Figure 1: Maximum and Minimum values as per the range [1,10] for all the three input sides

Then you can write the 13 test cases as following:

Figure 2: Test Cases for Triangle Problem using BVA-BVC approach

Upon close observation, you can see that two input variables are fixed to a nominal value while the other input varies. Good job so far! You have successfully written the test cases as per BVA-BVC.

Now let us do something more practical. We will first code the problem statement in java, and then develop test cases. Please refer to this article if you are new to the java unit test. This article will help you to set up your environment to support testing and debugging your java programs in a much easier way.

Writing the Test Cases in Java

The entire project can be found in this Github repository. Here, we will discuss only the critical code fragments aligned with the current topic of discussion.

If you open the App.java file in the repository, you will find a very elementary java code to identify the type of triangle on the basis of input sides. Run the code on your system to ensure that it is working.

Now you have to develop the 13 test cases that we have identified earlier in this tutorial. All the test cases can be found in AppTest.java file.

Let us take a look at one test case namely testIsosceles1. It maps to test case ID 1 in the above table. The code should look something like this:

.../
String type=null;
@Test //Test case ID 1public void testIsosceles1() {
type = App.classify(1, 5, 5);
assertEquals("Isosceles", type);
}
/......

The code above will first make a call to the ‘classify’ method with three inputs. The function will return the type of triangle and store the value in the variable ‘type’. Then using the method ‘assertEquals’, the test case will compare the expected output with the actual output.

Let’s see what will happen if the expected output does not match with the actual output. In the code below, I have given (5,5,5) as inputs which should lead to the failure of this test case. This is so because for (5,5,5) the actual output will be “Equilateral”, which is not the expected outcome (since the test case expected the output to be “Isosceles”). Ultimately, the test case fails and as a software tester, you have just found your first bug!

Gif 1: Running a Test Case in Java

Similarly, you should be able to write the remaining 12 test cases. Be careful to add @test annotation everytime you add a new test case in java. After adding all the necessary cases, the program passes all the test cases.

Gif 2: Running the 13 Test Cases in Java for Triangle problem using BVA-BCA approach

Conclusion

In this blog, we have covered a very popular and fundamental concept of software testing, i.e., Boundary Value Analysis using Boundary value checking. Also note that you can modify the program to take input sides (X,Y,Z) from the user and then test whether the inputs satisfy the conditions or not.

I hope this article has been helful to you. Till the next time!

Reference

[1] Naresh Chauhan (2010) SOFTWARE TESTING Principles and Practices, Oxford University Press.

--

--

Swati Rajwal
Geek Culture

Just another human being on this beautiful planet.