Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: The method assertEquals from the type Assert is deprecated

Tags:

java

junit

Since the method Assert.assertEquals is deprecated, which method are we supposed to use now?

The following code:

String arg1 = "test";
String arg2 = "me";

Assert.assertEquals(arg1, arg2);

Gives the following warnings:

Multiple markers at this line

  • The method assertEquals(String, String) from the type Assert is deprecated
  • The type Assert is deprecated
like image 251
Brad Parks Avatar asked Oct 18 '22 05:10

Brad Parks


2 Answers

You're using junit.framework.Assert instead of org.junit.Assert.

like image 351
Stefan Birkner Avatar answered Oct 20 '22 19:10

Stefan Birkner


this method also encounter a deprecate warning:

org.junit.Assert.assertEquals(float expected,float actual) //deprecated

It is because currently junit prefer a third parameter rather than just two float variables input.

The third parameter is delta:

public static void assertEquals(double expected,double actual,double delta) //replacement

this is mostly used to deal with inaccurate Floating point calculations

for more information, please refer this problem: Meaning of epsilon argument of assertEquals for double values

like image 55
tommy.qichang Avatar answered Oct 20 '22 19:10

tommy.qichang