Testing / JUnit6 Interview Questions
What FastCSV migration happened in JUnit 6 and what are the breaking changes?
JUnit 6 replaced the univocity-parsers library (used for CSV parsing in @CsvSource and @CsvFileSource) with FastCSV. This was necessary because univocity-parsers became unmaintained. FastCSV is faster and stricter, which causes a few breaking changes for tests with previously tolerated malformed CSV.
| Change | JUnit 5 behaviour | JUnit 6 behaviour |
|---|---|---|
| Extra characters after closing quote | Silently tolerated | Throws exception: 'foo'INVALID,'bar' is invalid |
| lineSeparator attribute in @CsvFileSource | Configurable | Removed: auto-detected (\r, \n, \r\n all work) |
| Header field processing | ignoreLeadingAndTrailingWhitespace etc. applied to data only | Now apply to header fields as well |
| Comment character in @CsvSource | # was default, no way to change it | New commentCharacter attribute; defaults to # but now configurable |
| Exception messages for malformed CSV | Implementation-specific | May differ with FastCSV's error messages |
// JUnit 5: this was silently tolerated (malformed CSV) @CsvSource({"'foo'INVALID,'bar'"}) void test(String a, String b) { ... } // ^ JUnit 6: throws exception -- extra chars after closing quote // JUnit 6: lineSeparator removed -- auto-detected // JUnit 5: @CsvFileSource(resources = "/data.csv", lineSeparator = "\n") // JUnit 6: @CsvFileSource(resources = "/data.csv") // lineSeparator attribute gone // JUnit 6: new commentCharacter attribute (needed if # appears in data) @CsvSource(value = { "#this is a comment -- skipped", "1, 2, 3", }, commentCharacter = '#') void additionTest(int a, int b, int expected) { ... } // Conflicting delimiter bug fix (from 6.0.1): // A regression in 6.0.0 caused exception when delimiter=# in @CsvSource // because # was ALSO the comment character with no way to override. // 6.0.1 added commentCharacter attribute to fix this.
More Related questions...