Test Overview
This test runs a simple JUnit test on a Calculator class to verify addition. Mutation testing with PIT will modify the code to check if the test detects errors, ensuring test quality.
This test runs a simple JUnit test on a Calculator class to verify addition. Mutation testing with PIT will modify the code to check if the test detects errors, ensuring test quality.
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; class Calculator { int add(int a, int b) { return a + b; } } public class CalculatorTest { @Test void testAdd() { Calculator calc = new Calculator(); assertEquals(5, calc.add(2, 3)); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | JUnit test runner initialized | - | PASS |
| 2 | CalculatorTest.testAdd() method invoked | Calculator instance created | - | PASS |
| 3 | calc.add(2, 3) called, returns 5 | Method returns sum of 2 and 3 | - | PASS |
| 4 | assertEquals checks if returned value equals 5 | Expected=5, Actual=5 | assertEquals(5, 5) | PASS |
| 5 | Test completes successfully | Test passed | - | PASS |
| 6 | PIT mutation testing runs, changes '+' to '-' in add method | Calculator.add method mutated to return a - b | - | PASS |
| 7 | Mutated testAdd() runs, calc.add(2, 3) returns -1 | Method returns 2 - 3 = -1 | - | FAIL |
| 8 | assertEquals checks if returned value equals 5 | Expected=5, Actual=-1 | assertEquals(5, -1) | FAIL |
| 9 | Mutation detected by test failure | Test failed due to mutation | - | PASS |