Skip to main content

Introduction

Filament provides excellent testing support through Laravel’s testing features and Livewire’s testing utilities. You can test resources, forms, tables, actions, and more using Pest or PHPUnit.

Setting up tests

Filament integrates seamlessly with Pest (recommended) or PHPUnit. Install Pest if you haven’t already:
Create a test file:

Testing resources

Test your Filament resources to ensure they work correctly:

Testing actions

Test actions in tables, forms, and pages:

Testing forms

Test form behavior, validation, and state management:

Testing tables

Test table columns, filters, and bulk actions:

Testing widgets

Test dashboard widgets and their data:

Testing authorization

Ensure authorization rules are enforced:

Testing relation managers

Test relation manager functionality:

Testing custom pages

Test custom Filament pages:

Best practices

  • Use descriptive test names with backticks for code references: it('can use \publish()` action’)`
  • Test both happy paths and edge cases
  • Use factories for creating test data
  • Test validation rules thoroughly
  • Test authorization at multiple levels (pages, actions, records)
  • Use database transactions to keep tests isolated
  • Test custom components and actions separately
  • Mock external services to keep tests fast
  • Use assertHasNoFormErrors() and assertHasNoActionErrors() to catch unexpected validation issues
  • Test accessibility by checking for proper labels and ARIA attributes
  • Group related tests using describe() blocks in Pest

Running tests

Run your tests with Pest: