Test Overview
This test uses the Given-When-Then pattern to check if a simple calculator adds two numbers correctly. It verifies that the sum is as expected.
This test uses the Given-When-Then pattern to check if a simple calculator adds two numbers correctly. It verifies that the sum is as expected.
import pytest class Calculator: def add(self, a, b): return a + b @pytest.fixture def calculator(): # Given: a calculator instance return Calculator() def test_addition(calculator): # When: adding two numbers result = calculator.add(3, 4) # Then: the result should be 7 assert result == 7, f"Expected 7 but got {result}"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and pytest fixture creates a Calculator instance | Calculator object is ready for use | - | PASS |
| 2 | Calls add method with inputs 3 and 4 | Calculator adds 3 + 4 internally | - | PASS |
| 3 | Checks if the result equals 7 | Result is 7 | assert result == 7 | PASS |