Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

AAA: Arrange, Act, Assert

Premium
3 min read

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 of our courses? (29 h 14 min)

You also get:

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

Already a member? Login here

Comments & Discussion

V
vance ✓ Link copied!

Could you kindly also indicate in the image which stage you are referring to?

M
Modestas ✓ Link copied!

Sorry, could you explain what do you mean by this?

C
campaigncenter ✓ Link copied!

Vance is probabbly referring to the PEST code where same code is used under Arrange, Act and Assert without any parts being bolded or otherwise marked. Though I doubt this will confuse many, you might just want to put 1 example with comments:

	test('homepage contains non empty table', function () {
			// Arrange
			Product::create([
					'name'  => 'Product 1',
					'price' => 123,
			]);

			// Act
			get('/products') 

			// Assert
					->assertStatus(200)
					->assertDontSee(__('No products found'));
	});
Z
Zhtekdev ✓ Link copied!

From this pag, nobody can unserstand what is Arrange, Act, Assert.

D
dcxweb ✓ Link copied!

@Zhtekdev

Arrange = create the data scenario (whatever it might be) Act = do the thing you want to test Assert = check the result is what you expect

Theres no extra hidden things here..I think the page repeats it to help the person LEARN by seeing already it's in 3 clear sections and there's 3 clear sections of code. For me I think this is totally fair in this case.