Can unit testing be successfully added into an existing production project? If so, how and is it worth it?

前端 未结 23 2464
遇见更好的自我
遇见更好的自我 2020-12-12 09:01

I\'m strongly considering adding unit testing to an existing project that is in production. It was started 18 months ago before I could really see any benefit of TDD

23条回答
  •  旧巷少年郎
    2020-12-12 09:48

    It's unlikely you'll ever have significant test coverage, so you must be tactical about where you add tests:

    • As you mentioned, when you find a bug, it's a good time to write a test (to reproduce it), and then fix the bug. If you see the test reproduce the bug, you can be sure it's a good, alid test. Given such a large portion of bugs are regressions (50%?), it's almost always worth writing regression tests.
    • When you dive into an area of code to modify it, it's a good time to write tests around it. Depending on the nature of the code, different tests are appropriate. One good set of advice is found here.

    OTOH, it's not worth just sitting around writing tests around code that people are happy with-- especially if nobody is going to modify it. It just doesn't add value (except maybe understanding the behavior of the system).

    Good luck!

提交回复
热议问题