0
0
Testing Fundamentalstesting~10 mins

Branch coverage in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if all possible branches (true and false paths) in a simple decision are executed. It verifies that the code correctly handles both conditions.

Test Code - PyTest
Testing Fundamentals
def is_even(num):
    if num % 2 == 0:
        return True
    else:
        return False


def test_is_even():
    assert is_even(4) == True  # Tests the 'true' branch
    assert is_even(5) == False # Tests the 'false' branch

if __name__ == '__main__':
    test_is_even()
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest environment is ready with the is_even function loaded-PASS
2Calls is_even(4)Function receives input 4Checks if 4 % 2 == 0 evaluates to TruePASS
3Returns True for input 4Function returns TrueAssert that returned value is TruePASS
4Calls is_even(5)Function receives input 5Checks if 5 % 2 == 0 evaluates to FalsePASS
5Returns False for input 5Function returns FalseAssert that returned value is FalsePASS
6Test endsAll assertions passed, both branches coveredBranch coverage achieved for both true and false pathsPASS
Failure Scenario
Failing Condition: If the function always returns True or always returns False, missing one branch
Execution Trace Quiz - 3 Questions
Test your understanding
What does branch coverage ensure in this test?
AOnly the false path of the if statement is tested
BOnly the true path of the if statement is tested
CBoth true and false paths of the if statement are tested
DThe function is tested with random inputs
Key Result
Branch coverage testing ensures that every possible decision path in the code is executed at least once, helping catch errors in all conditions.