0
0
JUnittesting~10 mins

@CsvSource for inline CSV data in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A"1; 2"
B"1, 2"
C"1|2"
D"1 2"
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons or other separators instead of commas.
Not putting the CSV line inside quotes.
2fill in blank
medium

Complete 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'
A"1 2 2", "3 4 12"
B"1; 2; 2", "3; 4; 12"
C"1|2|2", "3|4|12"
D"1, 2, 2", "3, 4, 12"
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons or pipes instead of commas inside lines.
Not separating lines with commas.
3fill in blank
hard

Fix 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'
A"Hello|World|HelloWorld", "Java|Test|JavaTest", "JUnit|5|JUnit5"
B"Hello; World; HelloWorld", "Java; Test; JavaTest", "JUnit; 5; JUnit5"
C"Hello, World, HelloWorld", "Java, Test, JavaTest", "JUnit, 5, JUnit5"
D"Hello World HelloWorld", "Java Test JavaTest", "JUnit 5 JUnit5"
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons or pipes instead of commas inside the CSV lines.
Not separating lines with commas.
4fill in blank
hard

Fill 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'
A"1, Alice, true", "2, Bob, true"
B"1, Alice, true", "2, Bob, false"
C"1; Alice; true", "2; Bob; false"
D"1|Alice|true", "2|Bob|true"
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons or pipes instead of commas.
Including false where the test expects true.
5fill in blank
hard

Fill 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'
A"10, 2, 5"
B"20, 4, 5"
C"30, 5, 6"
D"10; 2; 5"
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons inside the CSV lines.
Not separating lines with commas.