Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Junit5断言导入_Java_Junit_Junit5 - Fatal编程技术网

Java Junit5断言导入

Java Junit5断言导入,java,junit,junit5,Java,Junit,Junit5,因此,我将Junit5包含到我的maven项目中,它可以正常工作,但无论如何,当我尝试将断言导入测试时,我只能将org.junit.jupiter.api.assertions.*放入,而无法指定一些精确的断言,并且必须在代码中编写,例如assertions.assertThrows() 为什么我不能从列表中选择任何特定的断言 可能是什么问题?您可以使用静态导入导入特定断言: import static org.junit.jupiter.api.Assertions.assertFalse;

因此,我将Junit5包含到我的maven项目中,它可以正常工作,但无论如何,当我尝试将断言导入测试时,我只能将
org.junit.jupiter.api.assertions.*
放入,而无法指定一些精确的断言,并且必须在代码中编写,例如
assertions.assertThrows()

为什么我不能从列表中选择任何特定的断言


可能是什么问题?

您可以使用
静态导入导入特定断言:

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

这对我在eclipse中很有用…

如果您只想导入一个方法,则必须使用静态导入,如下所示:

import static org.junit.jupiter.api.Assertions.assertThrows;
然后,您可以像这样简单地使用它:

assertThrows(Exception.class, () -> ...)

您使用的是
import static
?哦,它立刻就起作用了:)但是为什么呢?您可能需要考虑在IDE中为断言包执行自动静态导入。在线搜索IDE的方法。