Is duplicated code more tolerable in unit tests?

前端 未结 11 2123
死守一世寂寞
死守一世寂寞 2020-11-30 18:28

I ruined several unit tests some time ago when I went through and refactored them to make them more DRY--the intent of each test was no longer clear. It seems there is a tr

11条回答
  •  猫巷女王i
    2020-11-30 18:57

    Ideally, unit tests shouldn't change much once they are written so I would lean towards readability.

    Having unit tests be as discrete as possible also helps to keep the tests focused on the specific functionality that they are targeting.

    With that said, I do tend to try and reuse certain pieces of code that I wind up using over and over, such as setup code that is exactly the same across a set of tests.

提交回复
热议问题