Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load CSV data from an external file using @CsvFileSource.
JUnit
@ParameterizedTest @CsvFileSource(resources = [1]) void testWithCsvFileSource(String input, int expected) { assertNotNull(input); assertTrue(expected >= 0); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the leading slash in the resource path.
Using an incorrect file path that does not exist.
✗ Incorrect
The resource path must start with a slash to load the CSV file from the classpath root.
2fill in blank
mediumComplete the code to skip the first line (header) of the CSV file in @CsvFileSource.
JUnit
@ParameterizedTest @CsvFileSource(resources = "/data/test-data.csv", [1] = 1) void testSkipHeader(String input, int expected) { assertNotNull(input); assertTrue(expected >= 0); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attribute names like skipLines or skipHeader.
Not skipping the header line causing test failures.
✗ Incorrect
The correct attribute to skip lines in @CsvFileSource is numLinesToSkip.
3fill in blank
hardFix the error in the @CsvFileSource annotation to correctly specify the file path.
JUnit
@ParameterizedTest
@CsvFileSource(resources = [1])
void testFilePath(String input) {
assertNotNull(input);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using relative paths without leading slash.
Using backslashes which are invalid in resource paths.
✗ Incorrect
The resource path must start with a slash and use forward slashes for classpath resources.
4fill in blank
hardFill both blanks to correctly configure @CsvFileSource to skip the header and use a UTF-8 encoding.
JUnit
@ParameterizedTest @CsvFileSource(resources = "/data/test-data.csv", [1] = 1, [2] = "UTF-8") void testWithEncoding(String input, int expected) { assertNotNull(input); assertTrue(expected >= 0); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using charset instead of encoding.
Using skipLines which is not a valid attribute.
✗ Incorrect
Use numLinesToSkip to skip header lines and encoding to specify file encoding in @CsvFileSource.
5fill in blank
hardFill all three blanks to create a @CsvFileSource that loads a CSV file, skips the first line, and uses UTF-8 encoding.
JUnit
@ParameterizedTest @CsvFileSource(resources = [1], [2] = 1, [3] = "UTF-8") void testFullConfig(String input, int expected) { assertNotNull(input); assertTrue(expected >= 0); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using relative path without slash.
Wrong attribute names for skipping lines or encoding.
✗ Incorrect
The resource path must start with a slash, numLinesToSkip skips the header, and encoding sets UTF-8.