Skip to main content

Important: Test "Happy" and "Sad" Paths

Premium
3 min read

The final part of this "philosophical" course section on "what to test" is about the happy/unhappy paths. The example is from our tests.

test('admin can see products create button', function () {
$admin = User::factory()->create(['is_admin' => true]);
 
actingAs($admin)
->get('/products')
->assertStatus(200)
->assertSee('Add new product');
});
 
test('non admin cannot see products create button', function () {
actingAs($this->user)
->get('/products')
->assertStatus(200)
->assertDontSee('Add new product');
});

For example, we covered the create button for products in previous lessons.

I added two tests for the opposite cases:

  • The "happy path": if I'm an admin, I can see the button
  • The "non-happy path": if I'm not an admin, I cannot see the products create button.

And this is important.

Quite often...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (36 h 00 min)

You also get:

61 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

No comments yet…