【发布时间】:2020-05-30 09:01:08
【问题描述】:
由于“未找到给定包含的测试”错误,我无法在 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);
}
}
build.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()
}
错误:
> 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)
一些注意事项:
- JUnit 4 和 5 都重现了问题
- IntelliJ IDEA 2019.3.3(社区版),Build #IC-193.6494.35,于 2020 年 2 月 11 日构建
- 测试在
src/test/java - 像Intelij 2019.1 update breaks JUnit tests 这样更换跑步者并没有帮助
- 没有
useJUnitPlatform()结果是一样的
【问题讨论】:
-
你的 Gradle 版本是什么,可以从命令行运行测试吗?
-
你试过添加
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.0") -
@BenWatson 感谢您的帮助!我阅读了有关 JUnit5 最新版本的更多信息,并发现从 5.4.0 开始,它已经聚合了包含 api 和引擎的工件“junit-jupiter”(它更适合我)。似乎“引擎”已从我的主项目中的其他依赖项加载。
-
那么它是否适用于聚合人工制品?
-
@johanneslink 是的,我可以使用聚合工件运行我的测试。我已经添加并接受了这个问题的答案。
标签: java gradle intellij-idea junit5