Should one override equals method for asserting the object equality in a unit test?

前端 未结 3 449
花落未央
花落未央 2020-12-06 00:49

Let\'s say we are testing the result of a method by asserting the equality of all the properties of the result object with properties of an expected result object. Should w

3条回答
  •  攒了一身酷
    2020-12-06 01:28

    I for one use custom assertions. There are two main reasons:

    • don't force test concerns into production. This means that the meaning of equals in a test method might not coincide with the meaning for production code;
    • equals may not be good enough for all the tests. Different tests will require different assertions, so you'll likely end up using custom assertions anyway.

提交回复
热议问题