由于“未找到给定包含的测试”错误,我无法通过 IntelliJ IDEA 中的 Gradle 运行测试。
我该如何解决?
Gradle 测试
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class GradleTests {
@Test
public void initTest() {
assertTrue(true);
}
}
构建.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 更新那样改变运行器会中断 JUnit 测试 没有帮助
- 没有
useJUnitPlatform()
结果是一样的
原文由 Arrovil 发布,翻译遵循 CC BY-SA 4.0 许可协议
感谢 Ben Watson ,我找到了解决方案。自 JUnit 5.4.0 以来,存在具有 api 和引擎依赖性的聚合工件。因此,只需向 build.gradle 添加一个依赖项即可解决此问题。