Is duplicated code more tolerable in unit tests?

前端 未结 11 2111
死守一世寂寞
死守一世寂寞 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条回答
  •  [愿得一人]
    2020-11-30 19:02

    "refactored them to make them more DRY--the intent of each test was no longer clear"

    It sounds like you had trouble doing the refactoring. I'm just guessing, but if it wound up less clear, doesn't that mean you still have more work to do so that you have reasonably elegant tests which are perfectly clear?

    That's why tests are a subclass of UnitTest -- so you can design good test suites that are correct, easy to validate and clear.

    In the olden times we had testing tools that used different programming languages. It was hard (or impossible) to design pleasant, easy-to-work with tests.

    You have the full power of -- whatever language you're using -- Python, Java, C# -- so use that language well. You can achieve good-looking test code that's clear and not too redundant. There's no trade-off.

提交回复
热议问题