JUnit assertEquals() not working when comparing two objects

后端 未结 3 1966
萌比男神i
萌比男神i 2020-12-19 07:32

I\'m trying to get the hang of Java. Unit testing is pretty important to me and so recently I\'ve started to use JUnit. It was tough to begin with but I\'m getting the hang

3条回答
  •  梦毁少年i
    2020-12-19 08:05

    If you are using a modern IDE for development (like Eclipse, IntelliJ etc), they can generate these methods for you. Check that out for two reasons: 1) to save time 2) To prevent possible bugs.

    In eclipse IDE, you can do so by selecting source -> generate hashCode() and equals().

    One more thing, when you implement of of these two, you have to implement the other one as well.

提交回复
热议问题