我想将我的 Gradle 项目测试从 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);
}
}
我正在使用 Intellij 2016.2 和 gradle 2.9
自版本以来4.6 for Gradle,不再需要插件了
Gradle支持Junit5本来就这样做:
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'
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)