Introduction to White Box Testing
White Box Testing or Transparent Testing is usually performed by the developer or someone who has knowledge of the coding language used in the given application. It is a process of testing the core design, build & coding database construction pattern, and implementation of a software application as a product. Verifying the program design, the programs in the form of codes, internal integration flow, and validating the database, the various combinations of input that should be permitted, the type of output expected, code modules responsible for performance and security of the application, etc., are accomplished in this testing.
What is White Box Testing?
It is also called code base testing, clear box testing, open box testing, and structural testing. The core idea of this approach to software testing is taking a look at the internal structure design and at the code of the program to test it.
In White box testing, the tester can see the entire code of the program, and he is tasked to verify the flow of how inputs and outputs work in the program. Unlike black-box testing, which is more focused on testing the functionality of the program, it is concerned with testing the internal structures of the program. Taking a look at the program in this way allows us to work on improving the design, usability and making the product more secure.
As you can guess, it is called white box or glass box testing because the tester can see the code and other parts of the program.
What makes White Box Testing Different from Black Box Testing?
If you have been tipping your toes in testing in the past, I am sure you have come across Black Box Testing. The biggest difference between White Box Testing and Black Box Testing is that unlike Black Box testing, which is done from a user’s point of view, it is done from a developer’s Point of View. In other words, rather than taking a look at the program from the outside, this approach sees the internal code and tests it.
How is it Performed?
We can divide the process into two major steps:
1. Understanding the code provided
At first, A tester in White Box Testing will need to learn the code of the application. Considering the fact it is all about understanding and testing all the internal code of the program, anyone who is tasked with testing the code should not only have good knowledge of programming but will also be needed to have a good hand with the language of the source code. Security is one of the important aspects of it, so the tester will also have to be good at secure coding practices.
2. Creating test cases and executing them
Once the code has been studied by the testing team, they can start testing the code to check its proper flow and structure. To do this, the testers will write some code for some test cases, which will try to traverse through all lines of code present in the program. It can also be done in Manual testing, which involves trial and error. The testers can also use some automated testing tools such as JUnit and NUnit.
Example
To better understand the concept of White Box Testing, take a look at the code below:
Code:
print (int x, int y) {
int sum = x + y;
If ( sum > 0 )
Print ( "Positive", result )
Else
Print ( "Negative", result )
}
As we discussed earlier, the goal of it is to traverse all branches, loops, and statements that are present in the code. Considering that, we can make 2 test cases, one where both inputs are positive and another where both inputs are negative integers.
Example:
- A = 10 and B = 20
- A = -10 and B = -20
White Box Testing Techniques
One of the most popular testing techniques for white box testing is called code coverage analysis, this technique tries to eliminate any gaps in the test case suite, and it identifies sections of an app that are not used by test cases. Once these gaps are found, we can create cases to see and verify parts of the code that is untested; this results in a more polished product at the end.
Following are some coverage analysis techniques:
- Statement Coverage: In this method, we try to traverse all statements in the code at least one time. This assures that all of the code is tested.
- Branch Coverage: This method is planned to traverse each branch of the decision points in the code. This makes sure that all decisions are at least tested once.
There are some other testing techniques too, here are just a few:
- Condition Coverage: In this testing technique, we make sure that all conditions are covered in the code, for example:
Code:
READ A, B
IF (A == 0 || B == 0)
PRINT ‘0’
As you can see, here we have 2 conditions: A == 0 and B == 0. Now, these conditions receive TRUE and FALSE as values.
One possible example can be:
#TC1 – A = 0, B = 110
#TC2 – A = 10, B = 0
- Multiple Condition Coverage: This is a bit more advanced than the last one. As you can guess, we test all possible combinations and all possible outcomes at least once.
Example:
Code:
READ A, B
IF (A == 0 || B == 0)
PRINT ‘0’
#TC1: A = 0, B = 0
#TC2: A = 0, B = 10
#TC3: A = 110, B = 0
#TC4: A = 110, B = 5
Hence. We require 4 test cases for 2 conditions.
Hence if there are n conditions, then we will require 2n test cases.
- Basis Path Testing: In this technique, we make a control flow graph, and then we calculate its cyclomatic complexity, which is the number of independent paths. Using the cyclomatic complexity, we can find the minimal number of test cases we can design for each independent path of the flow graph.
- Loop Testing: Loops are one of the most used tools in a programmer’s weaponry. As these are at the core of so many algorithms, it only makes sense to have a testing technique based on loops. There can be 3 types of loops: Simple, nested, and concatenated. Let’s take a look at how a tester will deal with the tech of these types:
1. Simple Loops: For a loop that is simple in design and has the size n, we can design some test cases that do the following:
- Skip said loop.
- Only traverse the loop once.
- Have 2 passes
- Have any number of passes that is less than its size.
- n-1 and n+1 pass through the loop.
2. Nested Loops: For code with nested loops, we start with the innermost loop and then go outwards till we can reach to the outermost loop.
3. Concatenated loops: In the case of these loops. We use a simple loop test once after another, and in case the concatenated loop is not independent, we can deal with them as we did with nested loops.
Advantages and Disadvantages of White Box Testing
Given below are the advantages and disadvantages mentioned:
Advantages:
- It has simple and clear rules to let a tester know when the testing is done.
- The techniques are easy to automate; this results in a developer having to hire fewer testers and smaller expenses.
- It shows bottlenecks which makes the optimization quite easy for the programmers.
- A testing team can get started with their work without having to wait for the development team to complete the UI development.
- As all code paths are covered in the code in most cases, the testing of code is more thorough.
- It helps in removing parts of the code that are not essential to the functionality of the program.
Disadvantages:
- It is quite taxing on resources. To get the testing done, you will need someone who knows your code very well to be on the testing team and who is a good programmer himself. This type of skill level increases the expenses of the testing.
- In many cases, being able to test every possible condition in the code is not possible due to time constraints or budget limitations.
- As it is based on checking the functionality of the existing code, you can’t find the missing functionality in the program.
- If any part of the code is redesigned and re-written, testers need to write the test cases again.
White Box Testing Tools
Given below are the white box testing tools:
1. JSUnit.net
This is a JavaScript testing tool. JSUnit is a part of Junit, and it’s an open-source unit testing framework that can be used to do White Box Testing. JSUnit is completely open-source under GNU Public License 2.0, which means even for commercial use, a developer does not have to pay any licensing fee.
2. CppUnit
Just like JSUnit, CppUnit is also considered to be a part of JUnit. The tool can output in plain text or XML format, depending on the tester’s need, and it can create unit tests with its own classes. The CppUnit is licensed under LGPL.
3. Veracode
While it’s not free for use, Veracode has some powerful tools that can be used to test .NET, C++, Java, and some other languages. It can be done applications made for desktop, web, and mobile apps too.
4. NUnit
It’s a unit testing framework, and it was written in C#. The tool supports all available .Net languages, and it supports data-driven tests too. Functionality-wise, it can work on both parallel and concurrent execution, and it can provide a class framework and test runner apps. One notable feature of the NUnit is that it is fairly easy to use.
5. JUnit
As you can guess from its name, JUnit is a unit testing automation tool for Java. The JUnit van is easily integrated with IDEs such as eclipse, Macen ACT, etc. It is able to support test-driven development, and it can synchronize existing tests with newly created once too. JUnit is completely open-source and free to use for any kind of Java Development.
6. CSUnit
Just like Nunit, CSUnit is built to support unit testing in the .Net Framework. It supports languages such as C# and VB.Net. CSUnit has built-in support for factoring practice and other types of practices that are used in the agile development approach of SDLC.
Conclusion
Testing has a very important place in the software development process, and White Box Testing is a valuable approach to getting it done. While this testing approach can be expensive and time-consuming, it remains to be the only way to make sure that all parts of the code were covered in the testing process.
The most important part of White Box Testing is how familiar the tester is with the code. Someone tasked with testing on the WBT approach who does not have a good hand with the source code and the programming language used will cause a lot of trouble. Also, depending only on this is not a good idea as it does not cover missing functionality. For a more covered approach to the development, both White Box Testing and Black box testing should be done as it will then cover maximum bugs, defects, and remaining features that need to be added before the product can be shipped.
Recommended Articles
This has been a guide to White Box Testing. Here we discussed how White Box Testing is performed with the help of examples and different White Box tools and techniques. You can also go through our other suggested articles to learn more –
- Software Testing Interview Questions
- Game Testing Interview Questions
- ETL Testing Interview Questions
- Software Testing Life Cycle
11 Online Courses | 2 Hands-on Projects | 65+ Hours | Verifiable Certificate of Completion
4.5
View Course
Related Courses