Arr*_*vil 17 java intellij-idea gradle junit5
由于“未找到给定包含的测试”错误,我无法在 IntelliJ IDEA 中通过 Gradle 运行测试。
我该如何解决?
GradleTests
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class GradleTests {
@Test
public void initTest() {
assertTrue(true);
}
}
Run Code Online (Sandbox Code Playgroud)
构建.gradle
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
//testCompile group: 'junit', name: 'junit', version: '4.12'
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.6.0'
}
test {
useJUnitPlatform()
}
Run Code Online (Sandbox Code Playgroud)
错误:
> Task :test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> No tests found for given includes: [GradleTests.initTest](filter.includeTestsMatching)
Run Code Online (Sandbox Code Playgroud)
一些注意事项:
src/test/javauseJUnitPlatform()结果是一样的Jon*_*Lee 29
我在类似的设置中遇到了这个错误,但无法用以前的答案解决它。通过这样做解决了它。
全部归功于:https : //linked2ev.github.io/devsub/2019/09/30/Intellij-junit4-gradle-issue/。
Sia*_*oft 19
Gradle 不知道在哪里寻找测试。将其添加到您的应用程序 build.gradle 文件根目录(不在 android 或依赖项闭包内):
tasks.withType(Test) {
useJUnitPlatform()
testLogging { // This is for logging and can be removed.
events("passed", "skipped", "failed")
}
}
Run Code Online (Sandbox Code Playgroud)
小智 14
/app/build.gradle
android {
testOptions {
unitTests.all {
useJUnitPlatform()
}
}
}
Run Code Online (Sandbox Code Playgroud)
Arr*_*vil 11
Thanks to Ben Watson I've found solution. Since JUnit 5.4.0 there is aggregate artifact with both api and engine dependencies. So just adding one dependency to build.gradle resolved this issue.
testCompile ('org.junit.jupiter:junit-jupiter:5.6.0')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14170 次 |
| 最近记录: |