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?
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:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With