I get the following error:
Both assertEquals(Object, Object) in Assert and assertEquals(double, double) in Assert match
For this line of code in my test, Junitnote that getScore() returns double:
Junit
getScore
double
assertEquals(2.5, person.getScore());
This is my correct import:
import static org.junit.Assert.*;
What causes this and how can I fix it?
I think your getScore () returns Double, not double. So the compiler is confused: should it convert both arguments to Object, or should it only convert Double to double?
double a = 2.0; Double b = 2.0; // assertEquals(a,b); // fails to compile // the compiler is confused whether to use assertEquals((Object) a,(Object) b); // OK // or assertEquals(a,(double) b); // OK
In any case, I would set a method to return the primitive type double.
Assert.assertEquals(double, double) ( ), , , :
Assert.assertEquals(double, double)
assertEquals(2.5, person.getScore(), 0.0);
, , - , person.getScore() 2.5. , 2.500001 ,
person.getScore()
2.5
2.500001
assertEquals(2.5, person.getScore(), 0.000001);
Source: https://habr.com/ru/post/1667982/More articles:Закрытие по сравнению с ES6. - javascriptSwagger - how to use swagger-codegen and build a project in the long run - javaAngular 2 router, error: do not activate an already activated outlet - angularlink to an existing .NET Framework project in ASP.NET core - c #How to connect the interaction of parent components through the component of the children's route? (Angular2) - angularClosing OpenFileDialog causes an application to freeze for 3-4 seconds - multithreadingHow to generate nk light process in erlang or elixir? - erlangSelenium ChromeDriver C # - How to send browser shortcut - c #OpenFileDialog.AutoUpgradeEnabled не работает под Vista или 7? - c#описание - Запрошенный ресурс недоступен - javaAll Articles