Search code examples
restunit-testingtestingfunctional-testing

Why do both unit and functional tests


I am doing extensive functional testing for my restful application, and because the app follows rest principles the overhead is minimal. I cannot think of a concrete reason why I should also invest time and effort into writing/testing unit tests. Am I missing an obvious point?


Solution

  • If you have a functional test that fails, you often have to spend time working through the chain of calls to find the block of code that caused the failure. When a unit test fails, you instantly know precisely where the failure is. This can save you time.

    Perhaps more importantly, this can save your teammates time. In my experience in working on many different teams for the past 3 decades, when someone else's functional tests fail, it takes me a while to understand the code. Unit tests, OTOH, are typically very small and very easy to understand. I can usually resolve a regression based on a unit test failure much quick than I can on a functional test failure.

    Also, unit tests typically run considerably faster than functional tests, giving you a tighter feedback loop.

    At the end of the day, you don't win bonus points for strictly following dogma established by others. Your goal is to write high quality software. If you can do that in your specific situation by only writing functional tests, go ahead and do it. Unit tests are a good idea in a great many software projects, but they aren't a panacea.