Automagic unit tests for upholding Object method contracts in Java?

前端 未结 8 1415
傲寒
傲寒 2021-01-04 14:11

When developing Java applications, I often override Object methods (usually equals and hashCode). I would like some way to systematically check that I\'m adhering to the co

8条回答
  •  Happy的楠姐
    2021-01-04 14:56

    This problem doesn't have "easy" solution unless you're putting strong constraints on your classes.

    For example, if you're using several constructors for a given class, how can you ensure that all your parameters are well taken into account in your equals/hash methods? How about defaults values? These are things that, unfortunately, cannot be automated blindly.

提交回复
热议问题