import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class Calculator {
public int add(int a, int b) {
return a + b;
}
}
public class CalculatorTest {
private final Calculator calculator = new Calculator();
@Test
void testAddWithArgumentAggregation() {
assertAll("Addition tests",
() -> assertEquals(5, calculator.add(2, 3), "2 + 3 should be 5"),
() -> assertEquals(0, calculator.add(-1, 1), "-1 + 1 should be 0"),
() -> assertEquals(0, calculator.add(0, 0), "0 + 0 should be 0")
);
}
}This test class defines a simple Calculator with an add method.
The test method testAddWithArgumentAggregation uses assertAll to group three assertions. Each assertion checks the add method with different inputs.
Using assertAll means all assertions run even if some fail, and the test report shows all failures together. This helps find multiple issues in one test run.
Clear messages in assertions help understand which case failed.