How do you retrofit unit tests into a code base?

前端 未结 7 679
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-17 16:56

Do you have any strategies for retrofitting unit tests onto a code base that currently has no unit tests ?

7条回答
  •  清酒与你
    2021-01-17 17:11

    Here's another great article on testing. In particular, a somewhat relevant quote from it:

    Here’s a terrible idea - decide you are going to spend a whole week building a test suite for your project. First of all, you’ll likely just get frustrated and burn out on testing. Secondly, you’ll probably write bad tests at first, so even if you get a bunch of tests written, you’re going to need to go back and rewrite them one you figure out how slow, brittle, or unreadable they are.

    I think you are better off building tests 1 at a time as you are fixing bugs or adding new functionality... don't try to build missing test cases, you should have an end goal for each test, rather than just to improve coverage.

提交回复
热议问题