0
0
Testing Fundamentalstesting~10 mins

Path coverage in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks that all possible paths in a simple decision function are executed and verified. It ensures the function behaves correctly for different input values, covering every branch.

Test Code - unittest
Testing Fundamentals
def classify_number(num):
    if num > 0:
        return "Positive"
    elif num == 0:
        return "Zero"
    else:
        return "Negative"

import unittest

class TestClassifyNumber(unittest.TestCase):
    def test_positive(self):
        self.assertEqual(classify_number(5), "Positive")

    def test_zero(self):
        self.assertEqual(classify_number(0), "Zero")

    def test_negative(self):
        self.assertEqual(classify_number(-3), "Negative")

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, tests ready to execute-PASS
2Runs test_positive: calls classify_number(5)Function receives input 5Return value is 'Positive'PASS
3Runs test_zero: calls classify_number(0)Function receives input 0Return value is 'Zero'PASS
4Runs test_negative: calls classify_number(-3)Function receives input -3Return value is 'Negative'PASS
5All tests completeAll paths in classify_number coveredAll assertions passedPASS
Failure Scenario
Failing Condition: Function returns wrong classification for any input path
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test_positive method verify?
AThat classify_number returns 'Zero' for input zero
BThat classify_number returns 'Positive' for input greater than zero
CThat classify_number returns 'Negative' for input less than zero
DThat classify_number raises an error for negative input
Key Result
Path coverage testing ensures every possible route through the code is tested, catching errors in all decision branches.