Skip to content

Optimize tests: Replace DatabaseMigrations with RefreshDatabase (70% faster) #1330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

AbdulrahmanReda70
Copy link
Contributor

Summary

Replaces DatabaseMigrations with RefreshDatabase across all test files for significant performance improvement while maintaining test isolation and reliability.

Why the Change?

DatabaseMigrations was very slow because:

  • Runs php artisan migrate:fresh --seed for every single test
  • Tears down and rebuilds database schema for each individual test
  • Massive I/O overhead with no reuse

RefreshDatabase is faster because:

  • Sets up database schema once at start
  • Uses transactions that auto-rollback after each test
  • Laravel's recommended approach for testing

Safety ✅

  • All integration tests still pass
  • Same test isolation guarantees
  • No breaking changes
  • Follows Laravel best practices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant