Testing / JUnit6 Interview Questions
How do you migrate from JUnit 5 to JUnit 6?
Migrating from JUnit 5 to JUnit 6 is significantly simpler than the JUnit 4 to 5 migration. Because the Jupiter annotation model is unchanged, most projects require only a version bump plus addressing a handful of breaking changes.
| Step | Action |
|---|---|
| 1. Update dependencies | Change junit-bom version from 5.x.x to 6.1.1; remove explicit version overrides |
| 2. Java 17 baseline | Ensure the project targets Java 17 or higher (JUnit 6 requires it) |
| 3. Remove deleted modules | Remove junit-platform-runner and junit-platform-jfr dependencies |
| 4. Fix CSV tests | Review @CsvSource and @CsvFileSource tests for malformed CSV (FastCSV is stricter) |
| 5. Remove lineSeparator | Remove lineSeparator attribute from @CsvFileSource (no longer exists) |
| 6. Fix Alphanumeric order | Replace MethodOrderer.Alphanumeric with DisplayName or MethodName |
| 7. Update build tools | Upgrade to Maven Surefire 3.x and Gradle 8.x for JUnit 6 support |
| 8. Update Kotlin | Upgrade to Kotlin 2.2+ minimum if using Kotlin tests |
| 9. Kotlin suspend tests | Remove runBlocking wrappers from suspend test methods |
| 10. Review migrationsupport | Remove junit-jupiter-migrationsupport usage (deprecated) |
| 11. Unified version | The Platform version is now 6.x.x, same as Jupiter -- update any explicit references |
<!-- Maven migration: change the BOM version --> <!-- BEFORE (JUnit 5) --> <dependency> <groupId>org.junit</groupId> <artifactId>junit-bom</artifactId> <version>5.11.4</version> <!-- old --> <type>pom</type><scope>import</scope> </dependency> <!-- AFTER (JUnit 6) --> <dependency> <groupId>org.junit</groupId> <artifactId>junit-bom</artifactId> <version>6.1.1</version> <!-- updated --> <type>pom</type><scope>import</scope> </dependency> <!-- Kotlin tests: remove runBlocking --> // BEFORE @Test fun fetchUser(): Unit = runBlocking { val u = service.fetchUser("1") assertEquals("Alice", u.name) } // AFTER @Test suspend fun fetchUser() { val u = service.fetchUser("1") assertEquals("Alice", u.name) }
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...
