Prev Next

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.

JUnit 5 to JUnit 6 migration checklist
StepAction
1. Update dependenciesChange junit-bom version from 5.x.x to 6.1.1; remove explicit version overrides
2. Java 17 baselineEnsure the project targets Java 17 or higher (JUnit 6 requires it)
3. Remove deleted modulesRemove junit-platform-runner and junit-platform-jfr dependencies
4. Fix CSV testsReview @CsvSource and @CsvFileSource tests for malformed CSV (FastCSV is stricter)
5. Remove lineSeparatorRemove lineSeparator attribute from @CsvFileSource (no longer exists)
6. Fix Alphanumeric orderReplace MethodOrderer.Alphanumeric with DisplayName or MethodName
7. Update build toolsUpgrade to Maven Surefire 3.x and Gradle 8.x for JUnit 6 support
8. Update KotlinUpgrade to Kotlin 2.2+ minimum if using Kotlin tests
9. Kotlin suspend testsRemove runBlocking wrappers from suspend test methods
10. Review migrationsupportRemove junit-jupiter-migrationsupport usage (deprecated)
11. Unified versionThe 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)
}

What is the minimum Java version you must target before migrating to JUnit 6?
Which of these migration steps is NOT required when moving from JUnit 5 to JUnit 6?

Invest now in Acorns!!! 🚀 Join Acorns and get your $5 bonus!
Acorns Logo

Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!

Earn passively and while sleeping

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.

Robinhood Logo

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 Logo

Webull! Receive free stock by signing up using the link: Webull signup.

More Related questions...

What is JUnit 6 and when was it released? What is the JUnit 6 architecture and what are its three main components? What are the core annotations in JUnit 6 and what does each do? What assertions does JUnit 6 provide and how do you use them? What are parameterized tests in JUnit 6 and how do you write them? What is the CancellationToken API introduced in JUnit 6? What are JSpecify nullability annotations in JUnit 6 and why do they matter? What is the native Kotlin coroutine support in JUnit 6? What are the Extension Model and extension points in JUnit 6? What are nested tests in JUnit 6 and what is the @TestClassOrder/@TestMethodOrder inheritance change? What is @ParameterizedClass in JUnit 6 and how does it differ from @ParameterizedTest? What is the FastCSV migration in JUnit 6 and how does it affect @CsvSource and @CsvFileSource? What modules were removed in JUnit 6 and what replaced them? How do you migrate from JUnit 5 to JUnit 6? What are assumptions in JUnit 6 and how do they differ from assertions? What is @TestInstance and how does it change test class lifecycle? What is the @RegisterExtension annotation and how does it differ from @ExtendWith? What is the @TempDir annotation in JUnit 6? What are dynamic tests in JUnit 6 and how do you create them with @TestFactory? How does parallel test execution work in JUnit 6? What is @ParameterizedClass in JUnit 6 and how does it differ from @ParameterizedTest? What FastCSV migration happened in JUnit 6 and what are the breaking changes? What is the TestInstance lifecycle in JUnit 6 and what are the two modes? How does test ordering work in JUnit 6 with @TestMethodOrder? What modules were removed in JUnit 6 and why? How do you migrate from JUnit 5 to JUnit 6? What are assumptions in JUnit 6 and how do they differ from assertions? What is the @TempDir annotation and how has it changed in JUnit 6? How does parallel test execution work in JUnit 6? What is the difference between @ExtendWith and @RegisterExtension in JUnit 6? What is the @RepeatedTest annotation in JUnit 6? What is the ExtensionContext and its Store used for in JUnit 6? What are tags and filtering in JUnit 6 and how are they used? What are dynamic tests in JUnit 6 and how does @TestFactory work? How does JUnit 6 integrate with Maven and Gradle? What is the @Suite API in JUnit 6 and how do you group tests into suites? What is the ParameterResolver extension interface and how do you use it for custom injection? What is conditional test execution in JUnit 6 and what built-in conditions are available? What are test interfaces and default methods in JUnit 6? How does JUnit 6 interact with Mockito and Spring Test? What is the TestExecutionListener SPI in JUnit 6? What are the key differences between JUnit 4 and JUnit 6? What is TestWatcher extension interface in JUnit 6 and when do you use it? What is the ConsoleLauncher and how do you run JUnit 6 tests from the command line? What is the @AutoClose extension and how does it simplify resource management in JUnit 6? How does JUnit 6 support for Kotlin differ from JUnit 5? What is the @DisplayNameGeneration annotation in JUnit 6? What is TestReporter in JUnit 6 and how do you use it? What are the unified version changes in JUnit 6 and why do they matter for dependency management? What are best practices and anti-patterns in JUnit 6 test design?
Show more question and Answers...

API

Comments & Discussions