Courses

Testing in Laravel 12 For Beginners

AAA: Arrange, Act, Assert

You're reading a FREE PREVIEW of a PREMIUM course.
Summary of this lesson:
- Understanding Arrange-Act-Assert testing pattern
- Using AAA pattern in Laravel tests
- Implementing each phase of the pattern
- Best practices for test structure and organization

In this lesson, we will not write code but look at a typical "plan" behind every test method.

One of the most common ways to write tests is to divide any function into three phases, and they all start with an "A" letter. It's a "AAA". You can call it a 3-step framework:

  • Arrange
  • Act
  • Assert

In most cases, you should stick to this plan for every function in your test.


Step 1. Arrange.

You can call it a "preparation" step.

Add any data you need, any configuration. Build the scenario.

test('homepage contains non empty table', function () {
Product::create([
'name' => 'Product 1',
'price' => 123,
]);
 
get('/products')
->assertStatus(200)
->assertDontSee(__('No products found'));
});

Step 2. Act.

This step is usually about...

The full lesson is only for Premium Members.
Want to access all 25 lessons of this course? (90 min read)

You also get:

  • 76 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord