[英]Junit5 assertions import
So, I included Junit5 to my maven project and it kind of works, but anyway when I try to import assertions to a test I can only put org.junit.jupiter.api.Assertions.*
without beign able to specify some precise assertion and在我必须编写的代码中,例如Assertions.assertThrows()
。
为什么我不能从列表中选择任何特定的断言?
可能是什么问题呢?
如果只想导入单个方法,则必须使用 static 导入,如下所示:
import static org.junit.jupiter.api.Assertions.assertThrows;
然后你可以像这样简单地使用它:
assertThrows(Exception.class, () -> ...)
您可以使用static
导入来导入特定断言:
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
这在日食中对我有用……
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.