Unit tests - The benefit from unit tests with contract changes?

前端 未结 9 1160
無奈伤痛
無奈伤痛 2021-01-30 00:27

Recently I had an interesting discussion with a colleague about unit tests. We were discussing when maintaining unit tests became less productive, when your contracts change.

9条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 00:45

    Unit tests surely can not catch all bugs, even in the ideal case of 100% code / functionality coverage. I think that is not to be expected.

    If the tested contract changes, I (the developer) should use my brains to update all code (including test code!) accordingly. If I fail to update some mocks which therefore still produce the old behaviour, that is my fault, not of the unit tests.

    It is similar to the case when I fix a bug and produce a unit test for, but I fail to think through (and test) all similar cases, some of which later turns out to be buggy as well.

    So yes, unit tests need maintenance just as well as the production code itself. Without maintenance, they decay and rot.

提交回复
热议问题