Is it OK to copy & paste unit-tests when the logic is basically the same?

前端 未结 9 2065
悲&欢浪女
悲&欢浪女 2021-02-02 12:09

I currently have like 10 tests that test whenever my Tetris piece doesn\'t move left if there is a piece in the path, or a wall. Now, I will have to test the same behaviour for

9条回答
  •  遇见更好的自我
    2021-02-02 12:35

    The xunitpatterns.org web site says "no" (copy / paste is not ok) because it can increase costs when tests need to be updated:

    • Test Code Duplication

    "Cut and Paste" is a powerful tool for writing code fast but it results in many copies of the same code each of which must be maintained in parallel.

    and for further reading it also links to the article

    • Refactoring Test Code

    By: Arie van Deursen, Leon Moonen, Alex van den Bergh, Gerard Kok

提交回复
热议问题