CTFL 4.3.1: Explain statement testing
K2Syllabus section 4.3.1
3 original PrepBench practice questions for learning objective 4.3.1 of the CTFL 4.0 syllabus. Try the examples below and check each answer against its syllabus reference.
Practice questions
Question 1
A test suite achieves 100% statement coverage of a module. In production the module still fails with a division by zero, which occurs only when a denominator is set to zero. Which explanation is correct?
- Exercising a statement does not detect defects in all cases, and data-dependent defects can survive full statement coverage
- 100% statement coverage cannot in fact have been reached, because the failing statement was clearly never executed
- 100% statement coverage ensures that the decision logic was tested, so the defect must lie in a different module
- Coverage was measured wrongly: statements exercised should be divided by the total number of branches
Show answer
- Correct answer: Exercising a statement does not detect defects in all cases, and data-dependent defects can survive full statement coverageThe statement was executed, but a data-dependent defect need not show itself.
- 100% statement coverage cannot in fact have been reached, because the failing statement was clearly never executedThe statement was executed; full statement coverage is what puts the defect on a covered line.
- 100% statement coverage ensures that the decision logic was tested, so the defect must lie in a different module100% statement coverage does not ensure that all the decision logic has been tested.
- Coverage was measured wrongly: statements exercised should be divided by the total number of branchesStatement coverage divides exercised statements by total executable statements.
When 100% statement coverage is achieved, every executable statement has been exercised at least once, so a statement containing a defect will have been executed. However, exercising a statement with a test case will not detect defects in all cases; the syllabus gives a division by zero that fails only when the denominator is zero as its example of a data-dependent defect. 100% statement coverage also does not ensure that all the decision logic has been tested.
Syllabus section 4.3.1
Question 2
What does achieving 100% statement coverage demonstrate about a test object?
- Every executable statement in the code has been exercised at least once
- Every possible path through the code has been executed at least once
- Every decision outcome, both true and false, has been exercised
- Every requirement in the specification has at least one test case
Show answer
- Correct answer: Every executable statement in the code has been exercised at least onceStatement coverage is the proportion of executable statements that have been run.
- Every possible path through the code has been executed at least onceExecuting every path is path coverage, a far stronger and usually impractical criterion.
- Every decision outcome, both true and false, has been exercisedExercising both outcomes of every decision is branch coverage, not statement coverage.
- Every requirement in the specification has at least one test caseCovering every requirement is black-box requirements coverage, not statement testing.
Statement coverage measures the percentage of executable statements exercised by the tests. 100% statement coverage means every statement has run at least once, but it does not guarantee that every branch outcome or path has been covered.
Syllabus section 4.3.1
Question 3
A component's test suite reaches 100% statement coverage and all tests pass. During later production use, a failure occurs in that component. Which explanation is consistent with what statement coverage guarantees?
- Some executable statements must have been left unexercised despite the reported figure
- The failure must come from a branch that contains no executable statement at all
- 100% statement coverage subsumes branch coverage, so the cause must lie outside the component
- Every statement ran at least once, but running a statement need not reveal a defect in it
Show answer
- Some executable statements must have been left unexercised despite the reported figure100% statement coverage means exactly that no executable statement was left unexercised.
- The failure must come from a branch that contains no executable statement at allBranches are transfers of control between nodes; this explanation does not follow from any coverage rule.
- 100% statement coverage subsumes branch coverage, so the cause must lie outside the componentThe subsumption runs the other way: branch coverage subsumes statement coverage, not the reverse.
- Correct answer: Every statement ran at least once, but running a statement need not reveal a defect in itExecution is guaranteed, detection is not, for example for data-dependent defects.
When 100% statement coverage is achieved, all executable statements in the code have been exercised at least once, so each statement containing a defect has been executed, which may cause a failure demonstrating that defect. However, exercising a statement with a test case will not detect defects in all cases — for example, defects that are data dependent, such as a division by zero that only fails when the denominator is set to zero.
Syllabus section 4.3.1
Original PrepBench practice material, not official exam questions or exam dumps. PrepBench is independent and is not affiliated with or endorsed by ISTQB®.