Testing / JUnit6 Interview Questions
What is the FastCSV migration in JUnit 6 and how does it affect @CsvSource and @CsvFileSource?
JUnit 6 replaced the univocity-parsers library (which had stopped receiving maintenance) with FastCSV for parsing CSV data in @CsvSource and @CsvFileSource. FastCSV is actively maintained, has better performance, and is stricter about malformed input.
| Aspect | JUnit 5 (univocity-parsers) | JUnit 6 (FastCSV) |
|---|---|---|
| Maintenance | Unmaintained library | Actively maintained |
| Strict parsing | Silently accepted some malformed CSV | Strict: throws exception on malformed input |
| Extra chars after quotes | Allowed silently: 'foo'INVALID | Exception thrown - no extra chars after closing quote |
| lineSeparator attribute | Present in @CsvFileSource | Removed: line separator auto-detected (\r, \n, \r\n) |
| Header fields | ignoreLeadingAndTrailingWhitespace did not apply to headers | Now applies to headers too |
| commentCharacter | Not configurable (# caused conflicts) | New commentCharacter attribute added; default still # |
// JUnit 5: this was silently accepted (malformed CSV) @CsvSource({"'foo'INVALID,'bar'"}) // JUnit 6: throws exception -- "extra characters after closing quote" // Fix: remove the extra characters @CsvSource({"'foo','bar'"}) // JUnit 5: @CsvFileSource with explicit line separator @CsvFileSource(resources = "/data.csv", lineSeparator = "\n") // JUnit 6: lineSeparator removed -- auto-detected @CsvFileSource(resources = "/data.csv") // Auto-detection handles \r, \n, and \r\n correctly // New in JUnit 6: configure commentCharacter // Previously # was hardcoded and conflicted with some delimiters @CsvSource( value = {"1, 2, 3", "# this is a comment"}, commentCharacter = '#' // can now be customised or disabled ) void additionTest(int a, int b, int expected) { ... }
More Related questions...