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

mennor's avatar

Laravel Dusk (Browser) vs Feature tests comparison

Hi all,

I'm (relatively) new to the world of testing. After installing Dusk in my Laravel application I see the following directories within my test directory:

  • Browser
  • Feature
  • Unit

The purpose of the Unit-directory is clear to me. However, I don't know in which directory (Browser of Feature) I should place my other tests. Is Dusk only for tests that involve JavaScript, or could I place every test there? Are there disadvantages of placing every test here?

Hopefully you can help me out!

0 likes
2 replies
MikeHopley's avatar
Level 17

Unit tests are normally for testing an individual class. Generally people do not allow database access in unit tests, but some people (like me) allow file access or other cross-class testing occasionally. These tests should be fast.

Feature tests are for testing how multiple parts of your application work together. This is where I put tests that involve database access, for example. These tests tend to be a bit slower. You can also include HTTP-based testing in here (which tends to be slower again).

Dusk is for testing in a real browser. This is particularly useful when your page relies on javascript, but it can also be used fine on pages without javscript. These are great tests for checking that your application works correctly, from the user's point of view. However, they are very slow compared to other tests.

In general, you want a mixture of different test types, with larger numbers of fast tests and smaller numbers of slow tests. You should normally have a lot more unit tests than browser tests, for example.

I add another test suite, called "External". I use this for tests that rely on external services, such as testing my usage of the Stripe API, or testing emails by retrieving them from MailTrap. These tests are slow and rarely change.

10 likes
AmirrezaN's avatar

I disagree with @mikehopley. Writing unit tests for everything is just worthless. You need to write Feature tests as much as possible since they'll cover actual usage of your application. You application may not even include a single unit test. Of course, it'll be much easier and faster to find source of problem if you write unit tests. I usually write unit tests for parts of application that are used often.

1 like

Please or to participate in this conversation.