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) { ... }
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...
