import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
public class NumberUtilsTest {
// Method to test
public static boolean isEven(int number) {
return number % 2 == 0;
}
@ParameterizedTest
@ValueSource(ints = {2, 4, 6, 8, 10})
void testIsEvenWithEvenNumbers(int number) {
assertTrue(isEven(number), "Number " + number + " should be even");
}
}The test class NumberUtilsTest contains the method isEven which returns true if the number is even.
The test method testIsEvenWithEvenNumbers is annotated with @ParameterizedTest and @ValueSource to run the test multiple times with different integer inputs.
For each input, the test asserts that isEven returns true, confirming the method works correctly for even numbers.
This approach avoids writing multiple test methods for each input and keeps tests clean and readable.