Why are functional tests not enough? What do unit tests offer?

前端 未结 8 1127
庸人自扰
庸人自扰 2020-12-25 09:02

I just had a conversation with my lead developer who disagreed that unit tests are all that necessary or important. In his view, functional tests with a high enough code cov

相关标签:
8条回答
  • 2020-12-25 09:51

    It can be a lot more difficult to find the source of problems if a functional test fails, because you're effectively testing the entire codebase every time. By contrast, unit tests compartmentalize the potential problem areas. If all the other unit tests succeed but this one, you have an assurance that the problem is in the code you're testing and not elsewhere.

    0 讨论(0)
  • 2020-12-25 09:54

    In TDD/BDD, unit tests are necessary to write the program. The process goes

    failing test -> code -> passing test -> refactor -> repeat

    The article linked also mentions the benefits of TDD/BDD. In summary:

    • Comes very close to eliminating the use of a debugger (I only use it in tests now and very rarely for those)
    • Code can't stay messy for longer than a few minutes
    • Documentation examples for an API built-in
    • Forces loose coupling

    The link also has a (silly) walk-through example of TDD/BDD, but it's in PowerPoint (ew), so here's an html version.

    0 讨论(0)
提交回复
热议问题