Recall & Review
beginner
What is branch coverage in software testing?
Branch coverage measures whether each possible branch (true/false) in decision points like if-else statements has been executed at least once during testing.
Click to reveal answer
beginner
How does branch coverage differ from statement coverage?
Statement coverage checks if each line of code runs, but branch coverage ensures every decision path (true and false) is tested, catching more logic errors.
Click to reveal answer
intermediate
Why is branch coverage important in pytest tests?
Branch coverage helps find untested decision paths in your code, making tests more thorough and reducing bugs from missed conditions.
Click to reveal answer
beginner
Example: What branches exist in this code snippet?<br>
if x > 0:
return 'positive'
else:
return 'non-positive'There are two branches: one where x > 0 is true, and one where x > 0 is false (else). Both must be tested for full branch coverage.
Click to reveal answer
intermediate
How can you measure branch coverage in pytest?
Use pytest with the coverage plugin and run:<br>
pytest --cov=your_module --cov-branch<br>This reports branch coverage along with line coverage.Click to reveal answer
What does branch coverage ensure in testing?
✗ Incorrect
Branch coverage ensures that all decision paths (true and false branches) are tested.
Which pytest option enables branch coverage measurement?
✗ Incorrect
The option --cov-branch tells pytest coverage to measure branch coverage.
If an if-statement has two branches, how many tests are needed for full branch coverage?
✗ Incorrect
Two tests are needed: one where the condition is true, one where it is false.
Branch coverage helps find bugs that statement coverage might miss because:
✗ Incorrect
Branch coverage tests all outcomes of decisions, catching logic errors missed by statement coverage.
Which of these is NOT a decision point for branch coverage?
✗ Incorrect
Variable assignment is not a decision point; branch coverage focuses on conditions that create branches.
Explain branch coverage and why it is important in testing with pytest.
Think about how if-else decisions create different paths in code.
You got /3 concepts.
Describe how you would write tests to achieve full branch coverage for a function with multiple if-else statements.
Consider each if-else as a fork in the road that needs exploring.
You got /3 concepts.