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) }
More Related questions...