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 String
s are Object
s)
Here is a link to a great Stackoverflow question regarding some of the differences between ==
and .equals()
.