Testing for Laravels
Laravel testing is the practice of verifying application behaviour with PHPUnit or Pest. Feature tests make HTTP requests against routes and assert responses and database state, unit tests check isolated classes, and framework helpers such as factories, fakes and RefreshDatabase keep tests fast and repeatable.
Stage: Quality and Deployment · Part of the Laravel roadmap · Last reviewed 19 November 2026
What to learn in Testing
- Write a feature test that posts to a route and asserts the response status
- Reset the database between tests using RefreshDatabase and model factories
- Fake mail, queues and storage to assert they were used without side effects
- Test authenticated routes by acting as a given user
- Run the suite from the command line and read failure output
Testing interview questions
What is the difference between a feature test and a unit test in Laravel?
A feature test boots the application and exercises a larger path, such as an HTTP request through routing, middleware and the database. A unit test checks one class or method in isolation without the framework. Laravel apps tend to rely heavily on feature tests.
How do you test code that sends email without sending it?
Call Mail::fake() at the start of the test, run the action, then assert with Mail::assertSent for the expected mailable. The fake records messages instead of delivering them, so the test is quick and does not depend on a mail server.
Where Testing fits in the Laravel roadmap
Testing belongs to the Quality and Deployment stage (advanced level). Ship.
Other units in this stage
Back to the full Laravel roadmap