简体   繁体   English

Eclipse Gradle 项目未找到 JUnit 测试

[英]Eclipse Gradle Project No JUnit Tests found

I'm using Kubuntu 18.04我正在使用 Kubuntu 18.04

Whenever I make a new JUnit Test Case inside a Gradle Project in Eclipse, and this test file goes to src/test/java, when I click: Test.java -> Run As -> JUnit Test每当我在 Eclipse 的 Gradle 项目中创建一个新的 JUnit 测试用例,并且这个测试文件转到 src/test/java 时,当我单击时:Test.java -> Run As -> JUnit Test

I get the message: "No JUnit Tests Found"我收到消息:“未找到 JUnit 测试”

The project and the tests work fine on Windows 10. Everything copy-pasted.该项目和测试在 Windows 10 上运行良好。所有内容都是复制粘贴的。 They just don't work in my Kubuntu 18.04.它们只是在我的 Kubuntu 18.04 中不起作用。

Capture of Gradle Project Gradle 项目的捕获

Message that not JUnit tests are found未找到 JUnit 测试的消息

Did you add annotation @Test for method?您是否为方法添加了注释@Test? Sample like that:这样的示例:

public class SampleTest {

    @Test
    public void test(){
        System.out.println("Test run");
    }
}

Is it not a problem with eclipse cache?是不是eclipse缓存的问题? I remember similar problem for maven (with turned off autobuilding), for such situation with maven, you would have to rebuild project, maven refresh - alt+f5 , and I don't know whether similar action is possible for gradle.我记得 maven 有类似的问题(关闭自动构建),对于 maven 的这种情况,你必须重建项目,maven refresh - alt+f5 ,我不知道 gradle 是否可以执行类似的操作。

I finally found the issue:我终于找到了问题:

Turns out it was the Java library that didn't detect the JUnit 4 tests.原来是 Java 库没有检测到 JUnit 4 测试。 By default, my eclipse uses the JavaSE-11, but the one that worked was the JavaSE-1.8 in the JRE System Library.默认情况下,我的 Eclipse 使用 JavaSE-11,但有效的是 JRE 系统库中的 JavaSE-1.8。

I don't know why JavaSE-11 causes this error, though.不过,我不知道为什么 JavaSE-11 会导致此错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM