3

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

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
Thermech
  • 4,371
  • 2
  • 39
  • 60
  • Idea 2016.2 supports JUnit 5 now. please. see http://stackoverflow.com/questions/38293901/gradle-project-running-junit-5-tests-in-intellij. Hope to help you. – walsh Jul 26 '16 at 01:30
  • please see http://stackoverflow.com/questions/38576108/integrate-junit-5-tests-results-with-intellij-test-report – mmerdes Jul 26 '16 at 07:23
  • 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 sketchy – Thermech Jul 27 '16 at 12:30

2 Answers2

4

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'
    }
}
LazerBanana
  • 6,865
  • 3
  • 28
  • 47
0

Currently Intellij IDEA supports JUnit5.

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

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96