Test Overview
This test checks a simple function that adds two numbers. It verifies that the function returns the correct sum.
This test checks a simple function that adds two numbers. It verifies that the function returns the correct sum.
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()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Python unittest framework initializes the test runner | — | PASS |
| 2 | Calls add(3, 5) | Function add is executed with inputs 3 and 5 | — | PASS |
| 3 | Receives result 8 from add function | Result stored in variable 'result' | — | PASS |
| 4 | Checks if result equals 8 using assertEqual | Assertion compares expected 8 with actual 8 | self.assertEqual(result, 8) | PASS |
| 5 | Test completes successfully | Test runner reports test passed | — | PASS |
unit testing in software development?assert?assert expression where expression must be True for test to pass.assert add(2, 3) == 5. assert add(2, 3) = 5 uses single = which is assignment, invalid here. assert(add(2, 3) = 5) uses single = which is assignment, invalid syntax. assert add(2, 3) equals 5 uses invalid keyword 'equals'.def multiply(a, b):
return a * b
assert multiply(3, 4) == 12
assert multiply(0, 5) == 0
assert multiply(-1, 3) == -3
assert multiply(2, 2) == 5def divide(a, b):
return a / b
assert divide(10, 2) == 5
assert divide(5, 0) == 0Pass the test and this pattern moves unknown