Testing / JUnit6 Interview Questions
How do you migrate from JUnit 5 to JUnit 6?
For teams already on JUnit 5.14 and Java 17+, the JUnit team describes the JUnit 6 migration as a "routine dependency bump". The annotation model is unchanged; what breaks is removed APIs and stricter CSV parsing.
<!-- Step 1: Update the BOM version in pom.xml --> <dependencyManagement> <dependencies> <dependency> <groupId>org.junit</groupId> <artifactId>junit-bom</artifactId> <version>6.1.1</version> <!-- was 5.14.x --> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <!-- Step 2: Update Maven Surefire/Failsafe to 3.x --> <!-- (versions older than 3.0.0 are no longer supported by JUnit 6) --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.5.0</version> </plugin> <!-- Gradle: --> // build.gradle.kts dependencies { testImplementation(platform("org.junit:junit-bom:6.1.1")) testImplementation("org.junit.jupiter:junit-jupiter") } tasks.test { useJUnitPlatform() } /* Step 3: Fix compiler errors from removed APIs: - Replace Alphanumeric with MethodName - Remove junit-platform-runner dependency - Remove @RunWith(JUnitPlatform.class) usages - Fix malformed @CsvSource data (extra chars after quotes) - Ensure Java 17+ baseline Step 4: Run the test suite and fix any FastCSV-related failures from stricter CSV parsing */
More Related questions...