Should you Unit Test simple properties?

前端 未结 8 1352
耶瑟儿~
耶瑟儿~ 2021-02-01 13:22

Should you Unit Test simple properties of a class, asserting that a value is set and retrieved? Or is that really just unit testing the language?

Example

8条回答
  •  鱼传尺愫
    2021-02-01 13:40

    The way I see is that how much unit testing (or testing in general) is down to how confident are you that the code works as designed and what are the chances of it breaking in the future.

    If you have a lower confidence of the code breaking (maybe due to the code being out sourced and the cost of checking line by line is high) then perhaps unit testing properties is appropriate.

    Once thing you can do is write a helper class that can go over all get/set properties of a class to test that they still behave as designed.

提交回复
热议问题