Bird
Raised Fist0
Software Engineeringknowledge~10 mins

White-box testing techniques in Software Engineering - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - White-box testing techniques
Start: Understand Code
↓
Select Technique
↓
Statement
↓
Execute
↓
Find Bugs
↓
Fix Code
White-box testing starts by understanding the code, then choosing techniques like statement, branch, or path testing to check code parts and find bugs.
Execution Sample
Software Engineering
if (x > 0) {
  y = 1;
} else {
  y = -1;
}
This code checks if x is positive and assigns y accordingly; white-box testing will check both branches.
Analysis Table
StepCondition (x > 0)Branch TakenActionOutput
1x = 5 > 0True branchy = 1y = 1
2x = -3 > 0False branchy = -1y = -1
3x = 0 > 0False branchy = -1y = -1
4All branches tested?YesTesting completeNo bugs found or bugs identified
💡 All branches have been tested to ensure code behaves correctly in each case.
State Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
xundefined5-30varies per test
yundefined1-1-1depends on x
Key Insights - 3 Insights
Why do we need to test both true and false branches?
Because each branch can behave differently, testing both ensures no hidden bugs in either path, as shown in execution_table steps 1 and 2.
What if a path is very long or complex?
Path testing tries to cover all possible paths, but for complex code, testers focus on important or risky paths to manage effort, as full path coverage can be impractical.
Is statement testing enough to find all bugs?
No, statement testing checks if each line runs but may miss bugs in decision logic; branch testing adds checking all decision outcomes, improving coverage.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of y after step 2?
A1
B-1
C0
Dundefined
💡 Hint
Check the 'Output' column in row for step 2 in execution_table.
At which step does the condition x > 0 evaluate to false for the first time?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look at the 'Condition (x > 0)' column in execution_table rows.
If we only test the true branch, what is missing according to the execution_table?
ATesting all statements
BTesting variable initialization
CTesting false branch and possible bugs there
DTesting output formatting
💡 Hint
Refer to the 'Branch Taken' column and see which branch is not tested if only true branch is checked.
Concept Snapshot
White-box testing techniques:
- Statement testing: run every line
- Branch testing: test each decision outcome
- Path testing: cover all possible paths
Goal: find bugs by checking internal code logic
Requires code knowledge and careful test design
Full Transcript
White-box testing techniques involve understanding the internal code and testing it thoroughly. The main methods include statement testing, which ensures every line of code runs; branch testing, which checks every decision's true and false outcomes; and path testing, which tries to cover all possible routes through the code. For example, a simple if-else statement is tested by running cases where the condition is true and false. This helps find bugs that might only appear in certain branches. Testing all branches is important because each can behave differently. Path testing can be complex for large code, so testers focus on critical paths. Statement testing alone may miss bugs in decision logic, so branch testing improves coverage. By following these techniques, testers can find and fix bugs early, improving software quality.

Practice

(1/5)
1. Which of the following best describes white-box testing?
easy
A. Testing that examines the internal structure of the code
B. Testing that focuses only on user interface behavior
C. Testing done without knowledge of the code
D. Testing that only checks software performance

Solution

  1. Step 1: Understand white-box testing definition

    White-box testing involves looking inside the code to test its logic and structure.
  2. 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.
  3. Final Answer:

    Testing that examines the internal structure of the code -> Option A
  4. Quick Check:

    White-box testing = internal code check [OK]
Hint: White-box tests look inside the code, not just outside [OK]
Common Mistakes:
  • Confusing white-box with black-box testing
  • Thinking white-box tests only check UI
  • Assuming white-box ignores code structure
2. Which syntax correctly represents a common white-box testing technique?
easy
A. User acceptance testing
B. Branch coverage
C. Load testing
D. Smoke testing

Solution

  1. Step 1: Identify white-box testing techniques

    Common white-box techniques include statement, branch, path, and condition coverage.
  2. 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.
  3. Final Answer:

    Branch coverage -> Option B
  4. Quick Check:

    Branch coverage = white-box technique [OK]
Hint: Branch coverage is a classic white-box technique [OK]
Common Mistakes:
  • Confusing black-box tests with white-box
  • Choosing performance or acceptance tests
  • Ignoring coverage-based techniques
3. Consider the following code snippet:
if (x > 0) {
  print("Positive");
} else {
  print("Non-positive");
}

Which white-box testing technique ensures both if and else branches are tested?
medium
A. Statement coverage
B. Path coverage
C. Branch coverage
D. Condition coverage

Solution

  1. Step 1: Understand the code branches

    The code has two branches: one for x > 0 true, one for false.
  2. Step 2: Identify technique testing all branches

    Branch coverage requires testing each branch (if and else) at least once.
  3. Final Answer:

    Branch coverage -> Option C
  4. Quick Check:

    Branch coverage = test all branches [OK]
Hint: Branch coverage tests all decision paths [OK]
Common Mistakes:
  • Confusing statement coverage with branch coverage
  • Thinking path coverage is simpler
  • Ignoring else branch testing
4. A tester wrote this code to check condition coverage:
if (a > 10 && b < 5) {
  print("Valid");
}

Which mistake would cause incomplete condition coverage?
medium
A. Testing only when both conditions are true
B. Testing when a is 5 and b is 3
C. Testing when a is 15 and b is 6
D. Testing when a is 20 and b is 2

Solution

  1. Step 1: Understand condition coverage

    Condition coverage requires testing each condition (a > 10 and b < 5) as true and false separately.
  2. 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.
  3. Final Answer:

    Testing only when both conditions are true -> Option A
  4. Quick Check:

    Condition coverage = test each condition true/false [OK]
Hint: Test each condition true and false separately [OK]
Common Mistakes:
  • Testing only combined true cases
  • Ignoring false condition tests
  • Assuming one test covers all conditions
5. You want to ensure every possible route through this code is tested:
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?
hard
A. Condition coverage
B. Statement coverage
C. Branch coverage
D. Path coverage

Solution

  1. Step 1: Identify all possible paths

    There are three paths: both x and y positive, x positive and y non-positive, x non-positive.
  2. Step 2: Understand path coverage

    Path coverage requires testing every possible route through the code, covering all combinations of decisions.
  3. Step 3: Compare with other techniques

    Statement and branch coverage do not guarantee all paths; condition coverage tests conditions but not all paths.
  4. Final Answer:

    Path coverage -> Option D
  5. Quick Check:

    Path coverage = test all routes [OK]
Hint: Path coverage tests every possible route through code [OK]
Common Mistakes:
  • Confusing branch with path coverage
  • Assuming statement coverage is enough
  • Ignoring nested conditions
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard