What is white box testing?
In white box testing, we test the internal structure of the program. Internal structure means program code, implementation, and design of the program.
Advantages of white box testing:
- Makes the code error free.
- Helps in code optimization.
Disadvantages of white box testing:
- A well-skilled developer is required for code testing.
- More time-Consuming.
Techniques of white box testing:
There are different white box testing techniques available. Some of these are as follows;
- Control Flow Testing
- Data Flow Testing
- Branch Coverage Testing
- Path Coverage Testing
- Statement Coverage Testing
- Decision Coverage Testing
- Condition Coverage Testing
- Loop Testing
- Path Sensitivity Testing
- Mutation Testing
- Data Flow Anomalies Testing
- API Testing
Control Flow Testing
It test the “Control flow” of a program. Test cases are all control structures included in the program like loops, if statements, and switch cases to ensure that all possible control flow paths are executed at least once.
Types of Control structures
Some Control structures are mentioned below;
- Sequential Structure
- Selection Structures
- If Statement
- If-else Statement
- Nested If-else Statement
- Switch Statement (or Case Statement)
- Repetition Structures
- For Loop
- While Loop
- Do-while Loop
- Loop Control Structures
- Break Statement
- Continue Statement
- Exit Statement
- Exception Handling
- Try-Catch Block
- Throw Statement
1. Sequential Structure Testing:
Normally, when a program is generating the accurate output, then the test can be considered as pass.
2. Selection Structures – If Statement Testing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <iostream> using namespace std; int main() { int number; // Ask the user to enter a number cout << "Enter a number: "; cin >> number; // check for being positive if (number > 0) { cout << "The number is positive." << endl; } // check for being Nagative else if (number < 0) { cout <<
"The number is negative." << endl; } // check for 0 else { cout << "The number is zero." << endl; } return 0; } |
Test Cases:
Test Case | Input | Expected Output |
1 | 5 | The number is positive. |
2 | -3 | The number is negative. |
3 | 0 | The number is zero. |
If-else Statement Testing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <iostream> using namespace std; int main() { int number; // Ask the user to enter a number cout << "Enter a number: "; cin >> number; // number is even or odd? if (number % 2
== 0) { cout << number << " is even." << endl; } else { cout << number << " is odd." << endl; } return 0; } |
Test Cases:
Test Case | Input | Expected Output |
1 | 6 | “6 is even.” |
2 | 9 | “9 is odd.” |
3 | 0 | “0 is even.” |
4 | -8 | “-8 is even.” |
5 | 347 | “347 is odd.” |
Nested If else statement
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> using namespace std; int main() { int num1, num2, num3; // Input three numbers cout << "Enter three numbers: "; cin >> num1 >> num2 >> num3; // Nested if-else to find the greatest number if (num1 >= num2) { if (num1 >= num3) cout << num1 << " is the greatest number."; else cout << num3 << " is the greatest number."; } else { if (num2 >= num3) cout << num2 << " is the greatest number."; else cout << num3 << " is the greatest number."; } return 0; } |
Test Cases:
Branch Coverage Testing