因为“找不到给定包含的测试”,我无法通过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
- 更改Runner,如Intelij 2019.1更新破坏JUnit测试没有帮助
- 没有
useJUnitPlatform()
的结果是相同的
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.0")
吗? - Ben Watson