所以,我在我的maven项目中包含了Junit5,它还算能用,但不管怎样,当我试图将断言导入到测试中时,我只能将org.junit.jupiter.api.Assertions.*放入测试,而不能指定一些精确的断言,并且在代码中我必须编写例如Assertions.assertThrows()的代码。
为什么我不能从列表中选择任何特定的断言?
可能的问题是什么?
发布于 2019-10-10 18:06:33
如果您只想导入单个方法,则必须使用静态导入,如下所示:
import static org.junit.jupiter.api.Assertions.assertThrows;然后您可以简单地使用它,如下所示:
assertThrows(Exception.class, () -> ...)发布于 2019-10-10 18:06:04
您可以使用static导入来导入特定的断言:
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;这对我在eclipse…中很有效。
https://stackoverflow.com/questions/58320345
复制相似问题