0
0
Testing Fundamentalstesting~10 mins

Unit testing in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks a simple function that adds two numbers. It verifies that the function returns the correct sum.

Test Code - unittest
Testing Fundamentals
def add(a, b):
    return a + b

import unittest

class TestAddFunction(unittest.TestCase):
    def test_add_two_positive_numbers(self):
        result = add(3, 5)
        self.assertEqual(result, 8)

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsPython unittest framework initializes the test runner-PASS
2Calls add(3, 5)Function add is executed with inputs 3 and 5-PASS
3Receives result 8 from add functionResult stored in variable 'result'-PASS
4Checks if result equals 8 using assertEqualAssertion compares expected 8 with actual 8self.assertEqual(result, 8)PASS
5Test completes successfullyTest runner reports test passed-PASS
Failure Scenario
Failing Condition: The add function returns a wrong sum, e.g., 7 instead of 8
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify?
AThe add function multiplies two numbers
BThe add function returns the correct sum of two numbers
CThe add function returns a string
DThe add function throws an error
Key Result
Unit tests should check one small piece of code and verify its output with clear assertions to catch errors early.