Is Java's assertEquals method reliable?

前端 未结 7 1747
[愿得一人]
[愿得一人] 2020-11-29 18:05

I know that == has some issues when comparing two Strings. It seems that String.equals() is a better approach. Well, I\'m doing JUni

7条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 18:38

    The JUnit assertEquals(obj1, obj2) does indeed call obj1.equals(obj2).

    There's also assertSame(obj1, obj2) which does obj1 == obj2 (i.e., verifies that obj1 and obj2 are referencing the same instance), which is what you're trying to avoid.

    So you're fine.

提交回复
热议问题