Best practice to choose fields for equals() implementation

前端 未结 5 2047
栀梦
栀梦 2021-02-05 13:43

When writing unit-tests, I often face the situation when equals() for some object in tests -- in assertEquals -- should work differently from how it wo

5条回答
  •  离开以前
    2021-02-05 14:04

    I would not think about the unit test when writing a equals() both are different.

    You define the equality of each object with one or group of properties by implementing equals() and hashcode().

    In your test if you want to compare all the properties of the object, then obviously you need to call each method.

    I think it is better to treat them separately.

提交回复
热议问题