Skip to main content

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

Read more here

Pest Grouping Tests

Premium
2 min read

Pest allows to set groups for tests. Group can be set for a folder, a file, or a test. Multiple groups can also be assigned.

The group() function is used to add a group. Here is an example of a specific test.

tests/Feature/ProductsTest.php:

test('api product store successful', function () {
$product = [
'name' => 'Product 1',
'price' => 123
];
 
postJson('/api/products', $product)
->assertStatus(201)
->assertJson($product);
})->group('api');
 
test('api product invalid store returns error', function () {
$product = [
'name' => '',
'price' => 123
];
 
postJson('/api/products', $product)
->assertStatus(422);
})->group('api');

When running tests, the flag --group should be used with the group name, to filter tests by a group.

We added API tests to the same ProductsTest file in this course. But, if we moved all API tests to the tests/Feature/Api folder, we could...

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

No comments yet…