Testing / JUnit6 Interview Questions
How does JUnit 6 integrate with Maven and Gradle?
JUnit 6 requires updated build tool versions that support the JUnit Platform. Maven needs Surefire 3.x and Gradle needs 8.x.
<!-- Maven: complete JUnit 6 setup --> <properties> <java.version>17</java.version> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.junit</groupId> <artifactId>junit-bom</artifactId> <version>6.1.1</version> <type>pom</type><scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>3.3.0</version> <!-- 3.x required for JUnit 6 --> </plugin> </plugins> </build>
// Gradle: complete JUnit 6 setup (build.gradle.kts) plugins { java } java { toolchain { languageVersion = JavaLanguageVersion.of(17) } } dependencies { testImplementation(platform("org.junit:junit-bom:6.1.1")) testImplementation("org.junit.jupiter:junit-jupiter") testRuntimeOnly("org.junit.platform:junit-platform-launcher") } tasks.test { useJUnitPlatform() // Required: tells Gradle to use JUnit Platform maxParallelForks = Runtime.getRuntime().availableProcessors() }
More Related questions...