← BACK
Pest PHP / Testing

Focus Test Runs Instantly with Pest ->only() Method

Punyapal Shah • • 1 min read
edit this tip →

Append ->only() to any Pest test declaration to execute only that specific test without writing long CLI filter strings.

Filtering specific test names via CLI flags like --filter requires typing exact strings. Appending ->only() to a test declaration silences all other tests in the file.

test('calculates order total with discounts', function () {
    expect(true)->toBeTrue();
})->only(); // Only this test will run!

test('another test', function () {
    // Skipped
});
  • Focuses test runner execution strictly on tagged test cases
  • Avoids typing long CLI --filter flags during debugging sessions
  • Remember to remove ->only() before committing changes

Related Tips

View all tips →

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