Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to use @CsvSource with two values.
JUnit
@ParameterizedTest
@CsvSource([1])
void testSum(int a, int b) {
assertEquals(a + b, a + b);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons or other separators instead of commas.
Not putting the CSV line inside quotes.
✗ Incorrect
The @CsvSource expects comma-separated values inside quotes for each line.
2fill in blank
mediumComplete the code to add multiple CSV lines in @CsvSource.
JUnit
@ParameterizedTest
@CsvSource([1])
void testMultiply(int a, int b, int expected) {
assertEquals(expected, a * b);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons or pipes instead of commas inside lines.
Not separating lines with commas.
✗ Incorrect
Multiple CSV lines are separated by commas and each line is a quoted string with comma-separated values.
3fill in blank
hardFix the error in the @CsvSource annotation to correctly pass three test cases.
JUnit
@ParameterizedTest
@CsvSource([1])
void testConcat(String a, String b, String expected) {
assertEquals(expected, a + b);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons or pipes instead of commas inside the CSV lines.
Not separating lines with commas.
✗ Incorrect
The correct CSV format uses commas inside quotes to separate values and commas between lines.
4fill in blank
hardFill both blanks to correctly use @CsvSource with mixed data types.
JUnit
@ParameterizedTest @CsvSource([1]) void testMixedTypes(int id, String name, boolean active) { assertTrue(active); assertNotNull(name); assertTrue(id > 0); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons or pipes instead of commas.
Including false where the test expects true.
✗ Incorrect
Each CSV line must be a quoted string with comma-separated values. The test expects 'active' to be true, so lines with false would fail.
5fill in blank
hardFill all three blanks to create a @CsvSource with three test cases and correct syntax.
JUnit
@ParameterizedTest
@CsvSource([1])
void testDivide(int numerator, int denominator, int expected) {
assertEquals(expected, numerator / denominator);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons inside the CSV lines.
Not separating lines with commas.
✗ Incorrect
Each CSV line is a quoted string with comma-separated values. Lines are separated by commas outside the quotes.