2016-07-25 115 views
1

我想將我的Gradle項目測試從JUnit 4轉換爲JUnit 5.由於有很多測試,我不想同時將它們全部轉換。使用gradle從intellij升級JUnit 4到JUnit 5

我嘗試配置我build.gradle這樣的:

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' 
} 

舊的測試仍在運行,但的IntelliJ不承認新的JUnit測試5像這樣的:

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

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

我m使用Intellij 2016.2 with gradle 2.9

+0

Idea 2016.2現在支持JUnit 5。請。請參閱http://stackoverflow.com/questions/38293901/gradle-project-running-junit-5-tests-in-intellij。希望能幫助你。 – walsh

+0

請參閱 http://stackoverflow.com/questions/38576108/integrate-junit-5-tests-results-with-intellij-test-report – mmerdes

+0

它dosent幫助我。我想知道如何升級,而復古兼容。此外,它得到了支持,但目前效果並不理想,它仍然很粗略 – Thermech

回答

0

由於4.6版本的搖籃,是沒有必要的插件了

搖籃支持Junit5本身只是做:

dependencies { 
    test.useJUnitPlatform() 

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

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