Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Functional Tests Replace Unit Tests in small projects [closed]

I am developing a new small project. I understand the importance of implementing automated tests to improve quality and maintainability. But I wander if in small applications the functional tests are sufficient. Is really necessary implement unit tests for all my functions? Do not functionality tests guaranty the quality of small applications?

like image 981
miguelbgouveia Avatar asked Mar 22 '23 11:03

miguelbgouveia


2 Answers

It really depends on the size of the project and the number of "moving parts" involved; but generally speaking I would say that unit tests are at least as, if not more important than, functional tests.

I was going to give an analogy of a simple software system but instead I'll tell you a story which may or may not really have happened to me. No doubt I will be downvoted into oblivion for it, what can I say. YOLO.

Anyway so I'm on holidays, in a hotel, and I want to trim my luxurious and totally non-ironic beard using a really nice beard trimmer I brought with me. Except that the muppet that designed the bathroom put the only socket on the opposite side of the room to the mirror! And to make things worse, the socket is the wrong shape because I'm in some weird foreign country where they drive on the wrong side of the road...

Not to worry. I have a travel power socket adapter. Except the cord on the trimmer is only 3 feet long and won't reach across the room. But wait! I have an extension cord, yay! Now I can preen myself in front of the mirror like a real man. **

I plug everything in and press the "on" button. The trimmer buzzes into life and then suddenly dies, leaving me with a lopsided mess of fuzz on my face.

Quick: what is the problem? Is it:

  • The Socket
  • My travel adapter
  • The fuse on the trimmer plug
  • The extension cord
  • The trimmer
  • The majestic awesomeness /horrendousness of my beard causing the trimmer to die on first contact?

This is the problem with only doing functional testing. Certainly by mucking around and switching things out I will eventually discover that the trimmer is working fine and the extension cord is the problem, but wouldn't it have been great if I had been able to check all of the bits and bobs involved in this operation first by Unit Testing them, so that even before I tried to turn on the trimmer, I knew that the cord was dodgy?

**this story is totally not true, I trim my beard with my shaving razor. Hell yeah.

like image 81
Stephen Byrne Avatar answered Apr 24 '23 22:04

Stephen Byrne


Functional tests might not be small/unit enough to catch implementation nuances at deep enough level.

While it's true they might cover enough ground to give you decent sense of confidence, you still might want to have unit tests to track bugs, prevent regression and deal with (problematic/rare) edge cases.

Besides, I don't see a need to introduce such distinction - functional vs unit vs integration vs what-not-else. You want automated tests, and that's all. You'll still have to implement them, most probably using same tools/frameworks for each test type.

like image 43
k.m Avatar answered Apr 24 '23 23:04

k.m