White Box Techniques
What is White Box testing?
[edit]White box testing is a software testing methodology that tests the internal structure and behavior of the software rather than its functionality.
White box testing is performed by testers with internal knowledge of the system and programming skills. Testers read the software specification and design test cases that exercise different code paths in the code, which is not possible with black box testing.
Are you considering a test management tool? A top choice for G2, Tuskr offers comprehensive features, easy ease of use, and affordable pricing. For example, imagine turning on the air conditioning in a large department store.
The black box test turns on the air conditioning and checks whether the temperature in different parts of the store is as expected at different times.
However, in white box testing, the tester verifies the following:
Each unit works as expected. The workload is evenly distributed among the individual air conditioning units. There are no cooling water leaks inside each unit. Carbon dioxide levels in the store are within normal limits. When is white box testing performed? White box testing can be performed at unit, integration, and system levels for software testing.
Most teams use code coverage tools because they are cost effective and can speed up white box testing. Code coverage tools monitor the execution of your test suite and tell you how many statements, branches, functions, and lines have been executed as part of your tests.
White-box testing techniques We shall now look at some popular testing techniques with some real-world examples.
Statement Coverage In this technique, test cases are written to ensure that every statement in the code is executed at least once.
In the code's flow-chart representation, the two arrows represent test cases required to cover all the statements.
Path Testing
The test cases in this technique ensure that every complete path in the program has been executed at least once. In the flow-chart representation of the code in the example below, the four arrows represent the test cases to cover all paths.
Condition Coverage
In this technique, all scenarios involving conditions are covered as shown in the following example:
function doSomething(int age, boolean hasParentalConsent) {
if (age < 18 AND hasParentalConsent == false)
{
error(' Must be an adult or parental consent is required');
}
...
} In this example, you will write the following test cases to cover the evaluation of the expression: age < 18 and hasParentalConsent == false:
age is 17, hasParentalConsent is false age is 17, hasParentalConsent is true age is 18, hasParentalConsent is false age is 18, hasParentalConsent is true age is 19, hasParentalConsent is false age is 19, hasParentalConsent is true Loop Testing Loops (e.g., 'while' and 'for' statements) are central to many algorithms. Defects often occur at the beginning or end of a loop or when it is skipped altogether.
For simple loops with N iterations, test cases are designed that:
Bypass the loop entirely Do a single pass Do M passes, where M < N Do N-1 passes Do N passes
Advantages of White Box Testing White-box testing can help detect inefficient code, dead code, and memory leaks. White-box testing can identify missing scenarios and gaps in the software specifications. White-box testing cases can be easily automated once test cases are in place. White-box testing can start early in the testing process as UI is not required.
Disadvantages of White-Box Testing White box testing is difficult and expensive. The software specification is often not up-to-date, making white-box testing ineffective. White-box testing often requires more skills than the original programmers who wrote the code as it requires a deeper level of understanding to design the test cases and analyze the results.