HTTP test assertions help you check if your web app responds correctly to requests. They make sure your app works as expected without opening a browser.
HTTP test assertions in Laravel
$response->assertStatus(200); $response->assertSee('Welcome'); $response->assertRedirect('/home');
Use $response from your HTTP test calls like $this->get() or $this->post().
Assertions check things like status codes, page content, redirects, and JSON responses.
$response = $this->get('/'); $response->assertStatus(200);
$response = $this->post('/login', ['email' => 'user@example.com', 'password' => 'secret']); $response->assertRedirect('/dashboard');
$response = $this->get('/profile'); $response->assertSee('User Profile');
$response = $this->getJson('/api/data'); $response->assertJson(['success' => true]);
This test class has two tests: one checks the home page loads with status 200 and shows a welcome message. The other checks that logging in redirects the user to the dashboard page.
<?php namespace Tests\Feature; use Tests\TestCase; class HomePageTest extends TestCase { public function test_home_page_loads_successfully() { $response = $this->get('/'); $response->assertStatus(200); $response->assertSee('Welcome to Our Site'); } public function test_login_redirects_to_dashboard() { $response = $this->post('/login', [ 'email' => 'user@example.com', 'password' => 'password123', ]); $response->assertRedirect('/dashboard'); } }
Always use HTTP test assertions inside your test methods after making a request.
Use assertStatus() to check HTTP codes like 200, 404, or 302.
Use assertSee() to check if certain text appears in the response body.
HTTP test assertions help confirm your app responds correctly to requests.
Common assertions include checking status codes, redirects, and page content.
They make your tests reliable and your app more stable.