White-box testing techniques in Software Engineering - Time & Space Complexity
When we analyze white-box testing techniques, we want to understand how the time needed to test code grows as the code size or complexity increases.
We ask: How does the effort to run these tests change when the program gets bigger?
Analyze the time complexity of the following code snippet.
for (int i = 0; i < n; i++) {
if (condition(i)) {
executeBranchA();
} else {
executeBranchB();
}
}
This code represents a simple white-box test that checks each part of the code by running through all possible branches once.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: The for-loop runs through each element from 0 to n-1.
- How many times: Exactly n times, once per element.
As the input size n grows, the number of operations grows in a straight line.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 checks and branch executions |
| 100 | About 100 checks and branch executions |
| 1000 | About 1000 checks and branch executions |
Pattern observation: The work grows evenly as the input grows; doubling input doubles work.
Time Complexity: O(n)
This means the testing effort grows directly in proportion to the size of the code or input being tested.
[X] Wrong: "Testing all branches means the time grows much faster than the code size."
[OK] Correct: Each branch is checked once per input, so time grows linearly, not exponentially.
Understanding how testing time grows helps you plan and explain your testing approach clearly in real projects and interviews.
"What if the code had nested loops inside the branches? How would the time complexity change?"
Practice
white-box testing?Solution
Step 1: Understand white-box testing definition
White-box testing involves looking inside the code to test its logic and structure.Step 2: Compare options to definition
Testing that examines the internal structure of the code matches this definition exactly, while others focus on external or unrelated aspects.Final Answer:
Testing that examines the internal structure of the code -> Option AQuick Check:
White-box testing = internal code check [OK]
- Confusing white-box with black-box testing
- Thinking white-box tests only check UI
- Assuming white-box ignores code structure
Solution
Step 1: Identify white-box testing techniques
Common white-box techniques include statement, branch, path, and condition coverage.Step 2: Match options to white-box techniques
Only branch coverage is a white-box technique; others are types of testing but not white-box.Final Answer:
Branch coverage -> Option BQuick Check:
Branch coverage = white-box technique [OK]
- Confusing black-box tests with white-box
- Choosing performance or acceptance tests
- Ignoring coverage-based techniques
if (x > 0) {
print("Positive");
} else {
print("Non-positive");
}Which white-box testing technique ensures both
if and else branches are tested?Solution
Step 1: Understand the code branches
The code has two branches: one forx > 0true, one for false.Step 2: Identify technique testing all branches
Branch coverage requires testing each branch (if and else) at least once.Final Answer:
Branch coverage -> Option CQuick Check:
Branch coverage = test all branches [OK]
- Confusing statement coverage with branch coverage
- Thinking path coverage is simpler
- Ignoring else branch testing
if (a > 10 && b < 5) {
print("Valid");
}Which mistake would cause incomplete condition coverage?
Solution
Step 1: Understand condition coverage
Condition coverage requires testing each condition (a > 10 and b < 5) as true and false separately.Step 2: Analyze testing only both true
If only tested when both are true, false cases for each condition are not tested, so coverage is incomplete.Final Answer:
Testing only when both conditions are true -> Option AQuick Check:
Condition coverage = test each condition true/false [OK]
- Testing only combined true cases
- Ignoring false condition tests
- Assuming one test covers all conditions
if (x > 0) {
if (y > 0) {
print("Both positive");
} else {
print("x positive, y non-positive");
}
} else {
print("x non-positive");
}Which white-box testing technique best guarantees this?
Solution
Step 1: Identify all possible paths
There are three paths: both x and y positive, x positive and y non-positive, x non-positive.Step 2: Understand path coverage
Path coverage requires testing every possible route through the code, covering all combinations of decisions.Step 3: Compare with other techniques
Statement and branch coverage do not guarantee all paths; condition coverage tests conditions but not all paths.Final Answer:
Path coverage -> Option DQuick Check:
Path coverage = test all routes [OK]
- Confusing branch with path coverage
- Assuming statement coverage is enough
- Ignoring nested conditions
Ready to prove it?
Pass the test and this pattern moves unknown
