Skip to main content

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? (30 h 41 min)

You also get:

55 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…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.