Performance: Feature tests
Feature tests impact the overall development feedback loop and CI/CD pipeline speed, affecting how quickly developers can detect issues and deploy.
Jump into concepts and practice - no test required
public function testUserCanCreatePost() {
$postService = $this->mock(PostService::class);
$postService->shouldReceive('create')->once()->andReturn(new Post(['title' => 'Test']));
$user = User::factory()->make();
$this->actingAs($user);
$response = $this->post('/posts', ['title' => 'Test', 'body' => 'Content']);
$response->assertStatus(201);
}public function testUserCanCreatePost() {
$user = User::factory()->create();
$this->actingAs($user);
$response = $this->post('/posts', ['title' => 'Test', 'body' => 'Content']);
$response->assertStatus(201);
$this->assertDatabaseHas('posts', ['title' => 'Test']);
}| Pattern | Database Calls | External Requests | Test Runtime | Verdict |
|---|---|---|---|---|
| Full HTTP request with DB | Multiple | None or some | High (200-500ms+) | [X] Bad |
| Mocked services, no DB | None | None | Low (50-150ms) | [OK] Good |
Feature tests in Laravel?public function testHomePageReturnsOk()
{
$response = $this->get('/');
$response->assertStatus(200);
}public function testUserRegistration()
{
$response = $this->post('/register', [
'email' => 'user@example.com',
'password' => 'secret',
]);
$response->assertRedirect('/home');
}