Eclipse Java IDE JUnit5:junit.jupiter.api.Assertions 不可访问 [英] Eclipse Java IDE JUnit5: junit.jupiter.api.Assertions is not accessible

查看:17
本文介绍了Eclipse Java IDE JUnit5:junit.jupiter.api.Assertions 不可访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是整个编程的新手,但这是我的问题:

I'm new to the whole programming stuff but here's my problem:

我曾经通过右键单击项目在 Eclipse 中添加我的 JUnit 测试用例,然后添加 New > JUnit 测试用例.

I used to add my JUnit test cases in Eclipse by right clicking on the project, and just add New > JUnit Test Case.

目前,我无法实现任何测试方法,因为 Eclipse 在线告诉我

Currently, I am not able to implement any test methods because Eclipse tells me on the line

import static org.junit.jupiter.api.Assertions.*;

错误信息

The type org.junit.jupiter.api.Assertions is not accessible.

我在 IDE 中遇到的错误:

Error I get in the IDE:

我尝试了以下方法:

  1. 使用全新的工作场所重新安装 Eclipse.
  2. 将 JUnit 添加到构建路径

没有任何帮助.

它在较旧的项目中运行良好并且运行.

It worked and works in older projects just fine.

包资源管理器的外观如下:

Here is how the Package Explorer looks:

我错过了什么?

推荐答案

您使用 Java 平台模块系统(JPMS) 通过在默认包中包含一个 module-info.java 文件可能没有所需的 requires ; 语句.JPMS 是在 Java 9 中引入的.

You use the Java Platform Module System (JPMS) by having a module-info.java file in the default package probably without the required requires <module>; statement. JPMS was introduced in Java 9.

执行以下操作之一:

  • 删除module-info.java文件(如果需要,您可以通过右键单击项目文件夹并选择Configure > Create module-info.java来重新创建它)
  • module-info.java中添加相应的requires语句,例如通过转到带有 import 语句的行并使用相应的 Quick Fix (Ctrl+1)
  • Delete the module-info.java file (if needed, you can recreate it via right-clicking the project folder and choosing Configure > Create module-info.java)
  • In module-info.java add the corresponding requires statement, e.g. by going to the line with the import statement and using the corresponding Quick Fix (Ctrl+1)

这篇关于Eclipse Java IDE JUnit5:junit.jupiter.api.Assertions 不可访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆