Menu

Laravel Testing Strategy: Feature vs Unit Tests
📰

Laravel Testing Strategy: Feature vs Unit Tests

DEV Community: laravel·Shakil Alam·1 day ago
#kmpPoimQ
#devtolaravel#devto#dev#test#tests
Reading 0:00
15s threshold

What You’ll Learn

The three types of tests and when to use each

Feature tests for HTTP flows and database interactions

Unit tests for pure business logic

Using Fakes to isolate tests from external services

Factory-first test data

Testing Policies and Actions

Running a meaningful test suite efficiently

The Three Test Types

Laravel supports three kinds of tests, each with a specific scope:

Feature Tests : Test the full HTTP request/response cycle. They make real database calls, go through middleware, run validation, hit controllers. Use them for any code that touches HTTP.

Unit Tests : Test a single class in isolation, with no database or HTTP. Fast. Use them for Services, Actions, and pure business logic.

Policy Tests : Test authorization rules. A subset of Feature or Unit tests, but worth calling out: every Policy deserves its own test.

The ratio across these projects is roughly 80% Feature tests, 20% Unit tests.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.