← BACK
Pest PHP / Testing

Clean Up Pest Test Configuration in tests/Pest.php

Punyapal Shah • • 1 min read
edit this tip →

Organize base test case bindings, helper functions, and global traits cleanly inside tests/Pest.php.

Duplicate uses() declarations across every test file clutters test suites. Centralize common test traits (like RefreshDatabase or TestCase classes) inside tests/Pest.php grouped by directory.

// tests/Pest.php
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

uses(TestCase::class, RefreshDatabase::class)->in('Feature');
uses(TestCase::class)->in('Unit');
  • Centralizes global traits like RefreshDatabase for specific test folders
  • Eliminates repetitive uses() imports across individual test files
  • Defines custom expectation helpers globally for all test suites

Related Tips

View all tips →

// Got a tip in mind? Contributions are always welcome