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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
