[英]Warning: The method assertEquals from the type Assert is deprecated
由於不推薦使用方法Assert.assertEquals
,我們現在應該使用哪種方法?
以下代碼:
String arg1 = "test";
String arg2 = "me";
Assert.assertEquals(arg1, arg2);
給出以下警告:
此行有多個標記
- 不推薦使用Assert類型的方法assertEquals(String,String)
- Assert類型已棄用
您正在使用junit.framework.Assert
而不是org.junit.Assert
。
此方法也會遇到棄用警告:
org.junit.Assert.assertEquals(float expected,float actual) //deprecated
這是因為目前junit更喜歡第三個參數,而不僅僅是兩個浮點變量輸入。
第三個參數是delta:
public static void assertEquals(double expected,double actual,double delta) //replacement
這主要用於處理不准確的浮點計算
有關更多信息,請參閱此問題: 對於double值,assertEquals的epsilon參數的含義
當我使用Junit4時,導入junit.framework.Assert; import junit.framework.TestCase; 警告信息為:不推薦使用Assert類型
當像這樣導入時:import org.junit.Assert; import org.junit.Test; 警告消失了
可能重復2個JUnit Assert類之間的差異
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.