I read an answer about Maven but I was wondering how I would achieve this task in Gradle - Executing JUnit 4 and JUnit 5 tests in a same build.
Currently my Gradle build only picks up tests with:
import org.junit.jupiter.api.Test;
My problem is that I'm using @RunWith
which needs JUnit4 to run but I want to execute it on a JUnit5 Vintage Engine.
How do I make my build such that I can run JUnit4 and JUnit5 together. Thanks.
Update:
Now there is a native Mockito Junit Jupiter
for JUnit 5 - https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter
The junit5-migration-gradle project demonstrates how to execute tests based on JUnit 5 using Gradle. In addition, it showcases that existing JUnit 4 based tests can be executed in the same test suite as JUnit Jupiter based tests or any other tests supported on the JUnit Platform.
Basically it boils down to having both engines, Jupiter and Vintage, on the runtime class-path:
dependencies {
testCompile("org.junit.jupiter:junit-jupiter-api:5.2.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.2.0")
}
dependencies {
testCompile("junit:junit:4.12")
testRuntime("org.junit.vintage:junit-vintage-engine:5.2.0")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With