#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

Feature Testing with HTTP Requests

Feature tests exercise a request the way a real user or client would — hitting a route, passing through middleware, and checking the resulting response.

Generating a Feature Test

php artisan make:test PostControllerTest

Making Requests in Tests

public function test_guest_cannot_create_a_post()
{
    $response = $this->post('/posts', ['title' => 'Hello']);

    $response->assertRedirect('/login');
}

public function test_authenticated_user_can_create_a_post()
{
    $user = User::factory()->create();

    $response = $this->actingAs($user)->post('/posts', [
        'title' => 'My First Post',
    ]);

    $response->assertStatus(201);
    $this->assertDatabaseHas('posts', ['title' => 'My First Post']);
}

Useful Assertions

Feature tests confirm the whole request works end to end. But real applications often call external services or complex dependencies that shouldn't run during a test — which is where mocking and stubbing help.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course