在 IntelliJ IDEA 中运行 Gradle 测试时出现“未找到给定包含的测试”

新手上路,请多包涵

由于“未找到给定包含的测试”错误,我无法通过 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)

一些注意事项:

原文由 Arrovil 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2.4k
2 个回答

感谢 Ben Watson ,我找到了解决方案。自 JUnit 5.4.0 以来,存在具有 api 和引擎依赖性的聚合工件。因此,只需向 build.gradle 添加一个依赖项即可解决此问题。

 testCompile ('org.junit.jupiter:junit-jupiter:5.6.0')

原文由 Arrovil 发布,翻译遵循 CC BY-SA 4.0 许可协议

我在类似的设置中遇到了这个错误,但无法用以前的答案解决它。通过这样做解决了它。

  1. 文件 > 设置 (Ctrl+Alt+S)
  2. 构建、执行、部署 > 构建工具 > gradle
  3. 使用 Intellij IDEA 运行测试

所有归功于: https ://linked2ev.github.io/devsub/2019/09/30/Intellij-junit4-gradle-issue/。

原文由 Jonathan Lee 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题