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

查看:155
本文介绍了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.

包浏览器的外观如下:

我缺少什么?

推荐答案

您使用 Java平台模块系统(JPMS),默认包中的 module-info.java 文件可能没有必需的要求< module> ;; 语句。 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 中添加相应的需求语句,例如通过使用 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天全站免登陆