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

前端 未结 9 2176
悲&欢浪女
悲&欢浪女 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条回答
  •  Happy的楠姐
    2021-02-02 12:15

    Test code is like any other code and should be maintained and refactored.

    This means that if you have shared logic, extract it to its own function.

    Some unit test libraries such as the xUnit family have specific test fixture, setup and teardown attributes for such shared code.

    See this related question - "Why is copy paste of code dangerous?".

提交回复
热议问题