How to use JUnit 5 with Gradle?

前端 未结 6 1613
长发绾君心
长发绾君心 2020-12-02 14:16

I am trying to use JUnit 5 with Gradle after I succeeded in running a JUnit 4 test.

Expected result: Tthe JUnit 4 test gave a nice \'passed\' in the

6条回答
  •  感动是毒
    2020-12-02 14:42

    You need the engines for both JUnit versions, and you need to apply the JUnit platform gradle plugin. I do not see that in your gradle file. Here is a working gradle build executing both JUnit 4 and 5:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath ("org.junit.platform:junit-platform-gradle-plugin:1.0.0-M4")
        }
    }
    
    apply plugin: 'org.junit.platform.gradle.plugin'
    ...
    
    dependencies {
    ...
        testCompile("junit:junit:4.12")
        testRuntime("org.junit.vintage:junit-vintage-engine:4.12.0-M4")
    
        testCompile("org.junit.jupiter:junit-jupiter-api:5.0.0-M4")
        testRuntime("org.junit.jupiter:junit-jupiter-engine:5.0.0-M4")
    
        // Enable use of the JUnitPlatform Runner within the IDE
        testCompile("org.junit.platform:junit-platform-runner:1.0.0-M4")
    }
    
    junitPlatform {
        details 'tree'
    }
    

    See the JUnit doc form more information on that.

提交回复
热议问题