0
0
Testing Fundamentalstesting~10 mins

Statement coverage in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if all the statements in a simple function are executed at least once. It verifies that the function returns the correct output for given inputs, ensuring full statement coverage.

Test Code - PyTest
Testing Fundamentals
def max_of_two(a, b):
    if a > b:
        return a
    else:
        return b


def test_max_of_two():
    assert max_of_two(5, 3) == 5
    assert max_of_two(2, 4) == 4
    assert max_of_two(7, 7) == 7

if __name__ == "__main__":
    test_max_of_two()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsTest environment ready, function max_of_two defined-PASS
2Call max_of_two(5, 3)Function executes with a=5, b=3Check if returned value == 5PASS
3Call max_of_two(2, 4)Function executes with a=2, b=4Check if returned value == 4PASS
4Call max_of_two(7, 7)Function executes with a=7, b=7Check if returned value == 7PASS
5All assertions passed, test endsAll statements in max_of_two executed at least onceVerify full statement coveragePASS
Failure Scenario
Failing Condition: If one of the assertions fails because the function returns wrong value
Execution Trace Quiz - 3 Questions
Test your understanding
What does statement coverage ensure in this test?
AAll possible input values are tested
BAll lines of code in the function are executed at least once
CThe function runs without errors
DThe function returns the same value every time
Key Result
Statement coverage helps ensure every line of code runs during testing, catching missed logic or errors in any part of the function.