我正在尝试配置gradle来运行JUnit 5测试.但是,当我尝试添加useJUnitPlatform()我的gradle文件以启用JUnit 5支持作为Directed here gradle docs时,我收到错误
Could not find method useJUnitPlatform() for arguments [] on task ':test' of type org.gradle.api.tasks.testing.Test.
Run Code Online (Sandbox Code Playgroud)
这是我的Gradle文件
apply plugin: 'java'
group 'com.notif'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
maven {
url 'https://packages.confluent.io/maven/'
}
}
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
testImplementation "org.mockito:mockito-core:2.21.0"
implementation 'org.apache.kafka:kafka-streams:1.0.0-cp1'
implementation 'org.apache.kafka:kafka-clients:1.0.0-cp1'
implementation 'org.apache.avro:avro:1.8.2'
implementation 'org.apache.logging.log4j:log4j-core:2.11.0'
implementation 'org.apache.logging.log4j:log4j-api:2.11.0'
implementation 'io.confluent:kafka-streams-avro-serde:4.1.0'
implementation 'biz.paluch.logging:logstash-gelf:1.11.2'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.6'
implementation 'org.asynchttpclient:async-http-client:2.2.0'
implementation 'org.apache.logging.log4j:log4j-jcl:2.11.1'
}
Run Code Online (Sandbox Code Playgroud)
任何想法为什么会这样,我错过任何依赖
Syl*_*are 14
这是我修复它的方法。我的测试任务如下build.gradle:
tasks.withType(Test) {
useJUnitPlatform()
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
}
Run Code Online (Sandbox Code Playgroud)
我有这些依赖项(您可能需要刷新 gradle,以便将它们考虑在内):
dependencies {
testCompile('org.junit.jupiter:junit-jupiter-api:5.4.0')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.4.0')
testRuntime('org.junit.vintage:junit-vintage-engine:5.4.0')
}
Run Code Online (Sandbox Code Playgroud)
然后我使用了 gradle 包装器(我使用的是 gradle 4.8),因此它从一台计算机到另一台计算机保持稳定:
tasks.withType(Test) {
useJUnitPlatform()
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
}
Run Code Online (Sandbox Code Playgroud)
如果您使用的是IntelliJ,则应检查给定项目使用的是哪个Gradle(可以是包装器,任务,本地)。为此,请转到“设置”并搜索Gradle。然后导航到Build,Execution,Deployment-> Build Tools-> Gradle