Test Overview
This test checks that a simple calculator's addition method always returns the same result for the same inputs. It verifies the test is deterministic, meaning it produces consistent results every time it runs.
This test checks that a simple calculator's addition method always returns the same result for the same inputs. It verifies the test is deterministic, meaning it produces consistent results every time it runs.
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; public class CalculatorTest { static class Calculator { int add(int a, int b) { return a + b; } } @Test void testAdditionIsDeterministic() { Calculator calc = new Calculator(); int result1 = calc.add(2, 3); int result2 = calc.add(2, 3); assertEquals(result1, result2, "Addition results should be the same for same inputs"); assertEquals(5, result1, "2 + 3 should equal 5"); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | JUnit test runner initialized | - | PASS |
| 2 | Calculator object is created | Calculator instance ready | - | PASS |
| 3 | Call add(2, 3) first time | Method returns 5 | - | PASS |
| 4 | Call add(2, 3) second time | Method returns 5 again | - | PASS |
| 5 | Assert result1 equals result2 | Both results are 5 | Check if 5 == 5 | PASS |
| 6 | Assert result1 equals 5 | Result1 is 5 | Check if 5 == 5 | PASS |
| 7 | Test ends successfully | Test passed with no errors | - | PASS |