Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 coverage should be enough since any inner refactorings (interface changes, etc.) will not lead to the tests being needed to be rewritten or looked over again.

I tried explaining but didn't get very far, and thought you guys could do better. ;-) So...

What are some good reasons to unit test code that functional tests don't offer? What dangers are there if all you have are functional tests?

Edit #1 Thanks for all the great answers. I wanted to add that by functional tests I don't mean only tests on the entire product, but rather also tests on modules within the product, just not on the low level of a unit test with mocking if necessary, etc. Note also that our functional tests are automatic, and are continuously running, but they just take longer than unit tests (which is one of the big advantages of unit tests).

I like the brick vs. house example. I guess what my lead developer is saying is testing the walls of the house is enough, you don't need to test the individual bricks... :-)

like image 448
Epaga Avatar asked Oct 08 '08 11:10

Epaga


People also ask

What is the difference between functional tests and unit tests?

Unit testing helps isolate specific code and determine if the unit works as intended. The goal is to facilitate early detection of code flaws that may be difficult to find and fix in later testing stages. Functional testing helps verify that each application feature works as intended.

What are the advantages of using unit tests?

Unit testing ensures that all code meets quality standards before it's deployed. This ensures a reliable engineering environment where quality is paramount. Over the course of the product development life cycle, unit testing saves time and money, and helps developers write better code, more efficiently.

Why should you have more unit tests than other tests types?

Generally speaking, unit tests are cheaper. They're easier to write—unless you're trying to add them to an existing app—which means developers don't spend quite as much time writing them. They're also cheaper to run: they don't usually require you to do special things for your environment or obtain external resources.

Why is unit testing harder than functional testing?

The author mentions that since state is maintained in object oriented programming, it is harder to write unit tests. He also says that since functional programming doesn't maintain state (not always), it is easier to write unit tests.


1 Answers

unit tests are for devs to see where the code failed

functional tests are for the business to see if the code does what they asked for

unit tests are checking that you've manufactured your bricks correctly

functional tests are checking that the house meets the customer's needs.

They're different things, but the latter will be much easier, if the former has been carried out.

like image 86
belugabob Avatar answered Sep 23 '22 19:09

belugabob