Is Java's assertEquals method reliable?

前端 未结 7 1740
[愿得一人]
[愿得一人] 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:40

    You should always use .equals() when comparing Strings in Java.

    JUnit calls the .equals() method to determine equality in the method assertEquals(Object o1, Object o2).

    So, you are definitely safe using assertEquals(string1, string2). (Because Strings are Objects)

    Here is a link to a great Stackoverflow question regarding some of the differences between == and .equals().

提交回复
热议问题