0
0
Laravelframework~10 mins

Feature tests in Laravel - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Feature tests
Write Feature Test Method
Set Up Test Environment
Send HTTP Request
Check Response Status
Assert Response Content
Test Pass or Fail
Feature tests in Laravel simulate user actions by sending HTTP requests and checking responses step-by-step.
Execution Sample
Laravel
public function test_homepage_shows_welcome()
{
    $response = $this->get('/');
    $response->assertStatus(200);
    $response->assertSee('Welcome');
}
This test checks if the homepage loads successfully and shows the word 'Welcome'.
Execution Table
StepActionInput/ConditionResultNext Step
1Call test methodtest_homepage_shows_welcome()Test startsSend HTTP GET request '/'
2Send HTTP GET requestURL: '/'Response received with status 200Assert status is 200
3Assert statusResponse status == 200PassAssert response contains 'Welcome'
4Assert contentResponse body contains 'Welcome'PassTest passes
5Test endsAll assertions passedSuccessEnd
💡 Test ends after all assertions pass or fail
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
$responsenullHTTP response object with status 200Same response objectSame response objectTest passed
Key Moments - 2 Insights
Why do we call $this->get('/') instead of directly calling the controller?
Because feature tests simulate real HTTP requests to the app, testing the full request lifecycle including middleware and routing, as shown in execution_table step 2.
What happens if assertStatus(200) fails?
The test stops and fails immediately at step 3 in the execution_table, so later assertions like assertSee won't run.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the response status after sending the GET request?
A500
B200
C404
D302
💡 Hint
Check row 2 under 'Result' column in execution_table
At which step does the test check if the page contains the word 'Welcome'?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Action' column in execution_table for the assertSee call
If the response status was 404 instead of 200, what would happen?
ATest would fail at assertStatus step
BTest would pass anyway
CTest would fail at assertSee step
DTest would continue but skip assertions
💡 Hint
Refer to key_moments about assertStatus failure and execution_table step 3
Concept Snapshot
Feature tests in Laravel simulate HTTP requests to your app.
Use $this->get('/url') to send requests.
Check response status with assertStatus().
Check page content with assertSee().
Tests fail immediately if assertions fail.
This tests the app end-to-end like a user.
Full Transcript
Feature tests in Laravel let you check how your app responds to HTTP requests. You write a test method that sends a request using $this->get() or other HTTP verbs. Then you check the response status with assertStatus() to make sure the page loaded correctly. Next, you can check if the response contains certain text with assertSee(). If any assertion fails, the test stops and reports failure. This way, feature tests simulate real user actions and test the full app flow including routing and middleware.