简体   繁体   English

Junit5 断言导入

[英]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 in the code I have to write for example Assertions.assertThrows() . 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()

Why can't I pick any specific assertion from the list?为什么我不能从列表中选择任何特定的断言?

What could be the problem?可能是什么问题呢?

If you only want to import a single method, you have to use a static import, like this:如果只想导入单个方法,则必须使用 static 导入,如下所示:

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

Then you can simply use it like:然后你可以像这样简单地使用它:

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

You can import specific assertions by using a static import:您可以使用static导入来导入特定断言:

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

This works for me in eclipse…这在日食中对我有用……

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM