How do you retrofit unit tests into a code base?

前端 未结 7 682
佛祖请我去吃肉
佛祖请我去吃肉 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:22

    The best way to retrofit an existing project without any unit tests is to do it when fixing bugs. Write a test that fails on the logic that has the bug in it with the steps to reproduce the bug. Then refactor the code until the tests pass. Now you can have confidence that the bug is fixed and it will not be introduced later on in the cycle and you started introducing unit tests into the project.

提交回复
热议问题