Which statement best describes statement coverage in software testing?
Think about how many lines of code your tests actually run.
Statement coverage counts how many lines of code (statements) are executed by tests compared to total executable lines.
Given the following code snippet and test cases, what is the branch coverage percentage?
def check_number(x):
if x > 0:
return 'Positive'
else:
return 'Non-positive'Test cases run: check_number(5)
Branch coverage counts how many decision branches are tested.
There are two branches: x > 0 true and false. Only the true branch is tested, so coverage is 50%.
Which assertion correctly verifies that all paths in the following function have been tested?
def classify(num):
if num > 0:
if num % 2 == 0:
return 'Positive Even'
else:
return 'Positive Odd'
else:
return 'Non-positive'Count all unique paths through the nested if statements.
There are three paths: positive even, positive odd, and non-positive. Testing all means 100% path coverage.
A test suite reports 80% statement coverage but 100% branch coverage. What is the most likely cause?
Think about how branches and statements differ in coverage.
Branch coverage counts decision points; statement coverage counts all executable lines. Missing simple statements lowers statement coverage but not branch coverage.
Which approach best ensures that test coverage metrics are enforced automatically in a Continuous Integration (CI) pipeline?
Automation is key in CI pipelines.
Automatically failing builds when coverage is low enforces quality and prevents regressions.