Why is assertEquals(double,double) deprecated in JUnit?

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.

JavaDoc:

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.

Leave a Comment