Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a parameterized test method with two parameters.
JUnit
[1] void testMethod(int number, String text) {} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Test instead of @ParameterizedTest for parameterized tests.
Placing the annotation inside the parameter list.
✗ Incorrect
To declare a parameterized test method, use the @ParameterizedTest annotation before the method declaration.
2fill in blank
mediumComplete the code to provide multiple parameters using CSV source.
JUnit
@ParameterizedTest
@CsvSource([1])
void testMethod(int number, String text) {} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons or pipes instead of commas as separators.
Putting all values in one string instead of separate strings.
✗ Incorrect
The @CsvSource annotation expects an array of strings, each string representing a line of CSV values separated by commas. So the correct format is "1,apple", "2,banana".
3fill in blank
hardFix the error in the parameterized test method declaration.
JUnit
@ParameterizedTest
@CsvSource({"1,apple", "2,banana"})
void testMethod([1] number, String text) {} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using String instead of int for numeric CSV values.
Using incompatible types like boolean or double.
✗ Incorrect
The first parameter corresponds to the first CSV value which is an integer, so the parameter type must be int.
4fill in blank
hardFill both blanks to correctly declare a parameterized test with multiple parameter types and source.
JUnit
@ParameterizedTest @CsvSource([1]) void testMethod([2] number, String text) {}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons instead of commas in CSV strings.
Using String type for numeric parameters.
✗ Incorrect
The @CsvSource needs strings with comma-separated values, so "3,orange", "4,grape" is correct. The parameter type for number is int.
5fill in blank
hardFill all three blanks to complete a parameterized test method with multiple parameter types and CSV source.
JUnit
@ParameterizedTest @CsvSource([1]) void testMethod([2] number, [3] text) {}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong separators in CSV strings.
Mixing up parameter types.
✗ Incorrect
The CSV source strings must be comma-separated values. The first parameter is an int matching the first CSV value, and the second parameter is a String matching the second CSV value.