ISTQB - International Software Testing Qualifications Board White-Box Test Design Questions and Answers — Questions and Answers
Question 1: A developer has written the following pseudocode. What is the MINIMUM number of test cases required to achieve 100% statement coverage? READ A READ B IF A > B THEN PRINT A ELSE PRINT B ENDIF
- 1
- 2 (Correct answer)
- 3
- 4
Correct answer: 2
To achieve 100% statement coverage, every executable statement in the code must be exercised at least once. In this pseudocode, one test case where A > B (e.g., A=10, B=5) will execute the `PRINT A` statement. A second test case where A is not greater than B (e.g., A=5, B=10) is required to execute the `PRINT B` statement. Therefore, a minimum of two test cases are needed to cover all executable statements.
Question 2: Which of the following BEST defines Decision Coverage?
- It ensures that every executable statement in the code has been tested at least once.
- It measures the percentage of independent paths through the code that have been exercised.
- It ensures that every possible outcome (TRUE and FALSE) of each decision point in the code has been exercised at least once. (Correct answer)
- It verifies that every function call within the code has been executed.
Correct answer: It ensures that every possible outcome (TRUE and FALSE) of each decision point in the code has been exercised at least once.
Decision coverage, also known as branch coverage, is a white-box testing technique that aims to exercise every possible outcome of a decision point (e.g., an IF statement or a loop condition) at least once. This means testing both the TRUE and FALSE branches for each decision.
Question 3: Which of the following statements about the relationship between statement coverage and decision coverage is correct?
- Achieving 100% statement coverage guarantees 100% decision coverage.
- Statement coverage and decision coverage are independent of each other.
- Achieving 50% decision coverage guarantees 100% statement coverage.
- Achieving 100% decision coverage guarantees 100% statement coverage. (Correct answer)
Correct answer: Achieving 100% decision coverage guarantees 100% statement coverage.
If you achieve 100% decision coverage, you have tested both the TRUE and FALSE outcomes of every decision. By doing so, you will have inherently executed all the statements within those decision branches. However, the reverse is not true; achieving 100% statement coverage does not guarantee 100% decision coverage, as a test might execute all statements without testing all possible decision outcomes.
Question 4: What is the primary goal of Modified Condition/Decision Coverage (MC/DC), a technique often required for safety-critical systems?
- To test every possible combination of conditions within a decision.
- To show that each condition within a decision can independently affect the outcome of that decision. (Correct answer)
- To execute every statement in the software at least once.
- To ensure that every function in the code has been called with every possible parameter value.
Correct answer: To show that each condition within a decision can independently affect the outcome of that decision.
The goal of MC/DC is to demonstrate that each individual condition within a complex decision can, on its own, affect the decision's outcome. This is achieved by creating test pairs where only one condition's value is changed, and this change causes the decision's outcome to flip, proving the independence of that condition.
Question 5: A tester is using white-box test design techniques. In which of the following areas are these techniques MOST effective for finding defects?
- Identifying missing requirements or specification ambiguities.
- Uncovering logic errors and incorrect assumptions in the code's control flow. (Correct answer)
- Finding defects in the graphical user interface (GUI) layout.
- Validating that the software meets the end-user's business needs.
Correct answer: Uncovering logic errors and incorrect assumptions in the code's control flow.
White-box testing is based on the internal structure and implementation of the code. Its primary strength lies in systematically exercising the code's logic, paths, branches, and conditions to find errors in the control flow, such as unreachable code, logic errors in loops and conditional statements, and incorrect data flow. Black-box techniques are better suited for finding issues related to requirements, usability, and business needs.
Question 6: Consider a simple function with a single `IF-THEN-ELSE` statement followed by another independent `IF-THEN-ELSE` statement. How many distinct paths exist through this function that need to be tested for 100% path coverage?
- 1
- 2
- 8
- 4 (Correct answer)
Correct answer: 4
Path coverage aims to test every possible unique route through a piece of code. The first `IF-THEN-ELSE` has two paths (TRUE and FALSE). The second independent `IF-THEN-ELSE` also has two paths. To find the total number of distinct paths, you multiply the number of paths from each sequential decision point. Therefore, there are 2 * 2 = 4 distinct paths to cover.
A developer has written the following pseudocode.
What is the MINIMUM number of test cases required to achieve 100% statement coverage?
READ A
READ B
IF A > B THEN
PRINT A
ELSE
PRINT B
ENDIF