簡體   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在我必須編寫的代碼中,例如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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM