我无法通过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)
一些注意事项:
src/test/java
中没有
useJUnitPlatform()
的最佳答案
我在类似的设置中遇到了此错误,但无法通过先前的答案解决。通过执行此操作解决了该问题。
全部归功于:https://linked2ev.github.io/devsub/2019/09/30/Intellij-junit4-gradle-issue/。
关于java - 在IntelliJ IDEA中运行Gradle测试时的"No tests found for given includes",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60228404/