we are building an API using Laravel, and we are facing an essential question:
Are we supposed to test everything (every method in every Model, Controller, and any other class)? or just test the API endpoints since testing endpoints means that everything else will be tested, because an API endpoint is using a Controller's method, that is in turn using a Model's method!
In fact I tend to the later one which is testing endpoints will help you test everything else, but I need to be sure that this is the right thing to do.
Edit:
Consider the following two points:
Any hints or comments will be appreciated.
Arguments and supporters exist for both sides. I suspect there are as many opinions on this subject as there are developers doing any form of developer testing.
In a nutshell:
I like the phrase twitter user @everzet recently used:
When they're green, all tests look the same. It's when they're red you see the real difference.
On the other hand, integrated tests provide more freedom when refactoring. If you test only at the API level, you can change the entire implementation without affecting your tests. If you test at the unit level, a refactoring might mean you have to update/rewrite a whole lot of tests.
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