Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

moren's avatar
Level 1

Feature vs Unit

What's the difference between feature and unit testing in laravel? Where to place controller's methods? ps. laravel 5.4 has tests/Unit and tests/Feature folders.

0 likes
8 replies
marthz's avatar
marthz
Best Answer
Level 17

Saw this gif a while ago in a post titled something like "2 unit test passed, no feature tests" :

https://gfycat.com/HotOrangeCoypu

The hand dryer and trash can both individually do their job correctly (they represent your classes, and you test them with unit tests).

But when you put them together something breaks unexpectedtly. And to test that you write feature tests that will, instead of testing a single small aspect of your app, try to mimic what happens when a user actually tries to use your app

117 likes
shakti's avatar

Unit Tests are written from a programmers perspective. They are made to ensure that a particular method (or a unit) of a class performs a set of specific tasks.

Functional Tests are written from the user's perspective. They ensure that the system is functioning as users are expecting it to.

45 likes
Jonjie's avatar

@shakti Do you agree that in unit test, you should not use Test\TestCase and instead use the PHPUnit\Framework\TestCase?

pashaster's avatar

As I understood, feature tests should be written for complex methods which have dependencies from other methods and classes and unit tests should be written for simple methods without dependencies...

Am I right?

2 likes
dkalpesh1992's avatar

Unit tests ensure that individual components of the app work as expected. Assertions test the component API.

Integration tests ensure that component collaborations work as expected. Assertions may test component API, UI, or side-effects (such as database I/O, logging, etc…)

Functional tests ensure that the app works as expected from the user’s perspective. Assertions primarily test the user interface. Know more about functional testing: https://www.simform.com/functional-testing/

3 likes
bor1904's avatar

Hi. I have additional aspect of this old question. How do you usually organize Feature test directory structure?

I saw that some of devs create "mirrored" structure from production part of framework, some of devs divide it into main phisical parts of app like guest, customer,admin ... next approach is a tons of files with free named testclasses, divided by models and test all operations related to this model.

What is your approach ? K

oliveroneal753's avatar

Functional tests ensure that the app works as expected from the user’s perspective. Assertions primarily test the user interface. Know more about functional testing:

Please or to participate in this conversation.