Grouping Tests

You can assign tests folders to various groups using Pest's group() method. Assigning a group to a set of relatively slow tests could be beneficial since it allows you to selectively execute them separately from the rest of your test suite. Typically, the process of assigning a set of tests to a group is done within your Pest.php configuration file.

For instance, consider the scenario where we assign the tests located in the tests/Feature folder to a group named "feature".

1uses(TestCase::class)
2 ->group('feature')
3 ->in('Feature');

As previously stated in the Filtering Tests documentation, you can use the --group option to execute tests belonging to a specific group.

1./vendor/bin/pest --group=feature

You also have the option to assign a particular test to a group by chaining the group() method onto the test function.

1it('has home', function () {
2 //
3})->group('feature');

You may also assign a test to multiple groups.

1it('has home', function () {
2 //
3})->group('feature', 'browser');

In some cases, you may want to assign a whole file to a group. To do so, you may combine the uses() and group() methods.

1uses()->group('feature');
2 
3it('has home', function () {
4 //
5});

When you are setting up a test suite, it may be necessary to share common hooks between different folders and groups. In such cases, Global Hooks can prove to be helpful: Global Hooks