BrownieCoffee's avatar

What test choose between Unit , Feature and Dusk test ?

Hi there,

I have doubts about different tests that Laravel offers. How to know what type of test to use, especially between Feature Test and Dusk test ?

My last question is : Is it necessary to create unit test ? I don't know how to apply that because I use actually my Feature Test...

Thank you by advance !

0 likes
3 replies
mikenewbuild's avatar

This is subjective, but I think the general consensus in the lessons on this site is to prefer feature tests, and use unit tests as part of a test driven approach. That's an approach that I have had some success with. I recommend the testing courses on this site as an introduction to that concept.

I have tried Dusk tests in projects but found little value personally, but there are scenarios where it's useful.

There are plenty of opinions about testing in general, so I think it comes down to working out the type of testing that gives you the most confidence in your code, and reduces the maintenance burden of your project. Easier said than done :)

audunru's avatar

Unit tests, to me, have primarily been useful to detect errors in my business logic. In my primary project, I've got lots of business rules around taxes and calculating them, and believe me, when I changed the way I store currencies in my database it was very useful to see that the tests still passed...

Feature tests have, in that same project, mostly been useful for testing the API. Not all parts of an API are used by myself, so to have tests that cover even the lesser used parts of it are useful.

I've got some Dusk tests, but maybe it's just me, but when they fail it's 90% of the time something with the test and not the code...

Finally, I've got some Jest unit tests for my Vue components.

To summarize, I fully agree with @mikenewbuild . What type of tests you need depend on the project. I think in my case I've overdone it a little, but at least I've learned a lot.

1 like

Please or to participate in this conversation.