Jiaju Shen Jiaju Shen - 1 year ago 275
Java Question

Why is my assertEquals() deprecated in JUnit?

I was wondering why

assertEquals(double, double)
is deprecated.

I used
import static org.junit.Assert.assertEquals;
and I used JUnit 4.11.

Below is my code:

import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class AccountTest {

public void test() {
Account checking = new Account(Account.CHECKING);
assertEquals(900.0, checking.getBalance());

returns a double value.

What could be wrong?

Answer Source

It's deprecated because of the double's precision problems.

If you note, there's another method assertEquals(double expected, double actual, double delta) which allows a delta precision loss.


Asserts that two doubles are equal to within a positive delta. If they are not, an AssertionError is thrown. If the expected value is infinity then the delta value is ignored.NaNs are considered equal: assertEquals(Double.NaN, Double.NaN, *) passes


delta - the maximum delta between expected and actual for which both numbers are still considered equal.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download