2
votes

I want to convert my Gradle project test from JUnit 4 to JUnit 5. As there are a lot of tests, I don't want to convert them all at the same time.

I try to configure my build.gradle like this:

apply plugin: 'java'

compileTestJava {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
}

repositories {
    mavenCentral()
}

dependencies {
    testCompile("junit:junit:4.12")
    testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.0-M2'
    testRuntime("org.junit.vintage:junit-vintage-engine:4.12.0-M2")
    testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.0-M2'
}

Old test are still running, but Intellij didn't recognize the new JUnit 5 test like this one:

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class JUnit5Test {
    @Test
    void test() {
        assertTrue(true);
    }
}

I'm using Intellij 2016.2 with gradle 2.9

2
Idea 2016.2 supports JUnit 5 now. please. see stackoverflow.com/questions/38293901/…. Hope to help you.walsh
It dosent help me. I wanna know how to upgrade while being retro compatible. Also, it's supported but it didn't work very well for now, it's still sketchyThermech

2 Answers

3
votes

Since version 4.6 for Gradle, there is no need for plugins anymore

Gradle supports Junit5 natively just do:

dependencies {       
    testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
    testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"

    testRuntimeOnly "org.junit.vintage:junit-vintage-engine:$junitVersion"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
}

test {
    useJUnitPlatform {
        includeEngines 'junit-jupiter', 'junit-vintage'
    }
}
0
votes

Currently Intellij IDEA supports JUnit5.

Take a look at nice article about integrating JUnit5 with IDEA: Using JUnit 5 in IntelliJ IDEA