Complete the code to use the correct annotation for parameterized tests in JUnit.
@[1]
public void testSum(int a, int b, int expected) {
assertEquals(expected, a + b);
}The @ParameterizedTest annotation tells JUnit to run the test multiple times with different parameters, reducing duplication.
Complete the code to provide multiple sets of parameters using the correct source annotation.
@ParameterizedTest @[1]({"1, 2, 3", "3, 4, 7", "5, 6, 11"}) public void testSum(int a, int b, int expected) { assertEquals(expected, a + b); }
@CsvSource allows passing multiple comma-separated values as parameters to the test method, enabling parameterization.
Fix the error in the parameterized test method signature to match the parameters provided.
@ParameterizedTest
@CsvSource({"2, 3, 5", "4, 5, 9"})
public void testSum([1]) {
assertEquals(expected, a + b);
}The test method must have parameters matching the number and types of values in each CSV line: int a, int b, int expected.
Fill both blanks to correctly import and use the assertion method in JUnit 5.
import static org.junit.jupiter.api.Assertions.[1]; @Test public void testAddition() { [2](5, 2 + 3); }
assertEquals is the correct assertion to check if two values are equal in JUnit 5.
Fill all three blanks to complete a parameterized test that uses a method source for input data.
@ParameterizedTest @MethodSource("[1]") public void testMultiply(int a, int b, int expected) { assertEquals([2], a * b); } static Stream<Arguments> [3]() { return Stream.of( Arguments.of(2, 3, 6), Arguments.of(4, 5, 20), Arguments.of(6, 7, 42) ); }
The method source name must match the string in @MethodSource. The assertion compares expected with the product. The method providing data is named multiplyData.