0
0
Testing Fundamentalstesting~20 mins

Branch coverage in Testing Fundamentals - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Branch Coverage Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Branch Coverage Basics

Which statement best describes branch coverage in software testing?

AIt checks if all functions in the program have been called at least once.
BIt counts how many lines of code have been executed during testing.
CIt measures whether each possible branch (true/false) of every decision point has been executed at least once.
DIt verifies that all variables have been assigned values during testing.
Attempts:
2 left
💡 Hint

Think about decisions in code like if statements and their possible paths.

Predict Output
intermediate
1:30remaining
Branch Coverage Test Result

Consider this Python function:

def check_number(x):
    if x > 0:
        return "Positive"
    else:
        return "Non-positive"

If a test suite calls check_number(5) only, what is the branch coverage?

A75% - partial testing of branches
B50% - only the 'x > 0' true branch was tested
C0% - no branches were tested
D100% - all branches were tested
Attempts:
2 left
💡 Hint

Think about which parts of the if statement run when x=5.

assertion
advanced
2:00remaining
Correct Assertion for Branch Coverage

Given this test code snippet for a function is_even(n) that returns True if n is even, which assertion best checks that both branches of the function are tested?

Testing Fundamentals
def test_is_even():
    # Which assertions ensure full branch coverage?
    pass
Aassert is_even(0) == True
Bassert is_even(2) == True
Cassert is_even(3) == False
Dassert is_even(2) == True and is_even(3) == False
Attempts:
2 left
💡 Hint

To cover branches, test both even and odd inputs.

🔧 Debug
advanced
2:00remaining
Identify Branch Coverage Issue in Test Cases

Here is a function and its test cases:

def classify_age(age):
    if age < 13:
        return "Child"
    elif age < 20:
        return "Teen"
    else:
        return "Adult"

# Test cases
assert classify_age(10) == "Child"
assert classify_age(25) == "Adult"

What is the branch coverage status of these tests?

AThe tests miss the 'Teen' branch, so branch coverage is incomplete.
BAll branches are covered by the tests.
CThe tests miss the 'Child' branch, so coverage is incomplete.
DThe tests miss the 'Adult' branch, so coverage is incomplete.
Attempts:
2 left
💡 Hint

Check if all if and elif branches have been tested.

framework
expert
2:00remaining
Measuring Branch Coverage with a Testing Framework

Using Python's unittest and coverage tools, which command correctly measures branch coverage for test_module.py?

Acoverage run --branch -m unittest test_module.py
Bcoverage run -m unittest test_module.py
Cunittest --branch test_module.py
Dcoverage branch run -m unittest test_module.py
Attempts:
2 left
💡 Hint

Check the coverage tool's option for branch coverage.