[Laravel](/performance/software development) Testing: Robust applications by testing (2026)
Published: June 2026 | Reading time: approx. 14 minutes Category: Quality assurance
Automated tests are an indispensable part of professional software development. They give you the assurance that your application works as expected, and allow you to make changes without having to be afraid to destroy something. Laravel offers an excellent testing infrastructure from home.
Types of tests in Laravel
Test type Description Location
**Unit tests * * Testing individual classes/methods isolated tests/unit/
**Feature tests * * Test all HTTP requests and answers tests/feature/
**Browser tests * * Test the application in real browser (Dusk) tests/Browser/
Run tests
Run all tests
php artisan test
♪ Unit tests only php artisan test --testsuite=Unit
♪ Only feature tests php artisan test --testsuite=Feature
♪ A specific test php artisan test --filter=UserTest
Your First Feature Test
php artisan make:test UserRegistrationTest
namespace Tests\Feature;
use Tests\TestCase; use Illuminate\Foundation\Testing\RefreshDatabase;
class UserRegistrationTest extends TestCase ♪ use RefreshDatabase;
public function test registration page can be rendered(): void ♪ $response = $this->get('/register');
$response>assertstatus(200); }
public function test new users can register(): void ♪ $response = $this->post('/register'), [ ‘name’ => ‘Test User’, ‘email’ => ‘test@example.com’, ‘password’ => ‘password’, 'password confirmation' => 'password', ),
$this->assertAuthenticated(); $response>assertRedirect('/dashboard'); } }
Database Testing with RefreshDatabase
The RefreshDatabase train resets the database after each test:
use Illuminate\Foundation\Testing\RefreshDatabase;
class PostTest extends TestCase ♪ use RefreshDatabase;
public function test posts can be created(): void ♪ $user = User:factory()->create();
$response = $this->actingAs($user)->post('/posts'), [ 'title' => 'My first contribution', 'content' => 'This is the content', ),
$this->assertDatabaseHas('posts'), [ 'title' => 'My first contribution', ), } }
Model Factories for Test Data
// database/factories/PostFactory.php class PostFactory extends factory ♪ public function definition(): array ♪ return ‘title’ => fake()->sentence(), ‘content’ => fake()->paragraph(3, true), 'user id' => User:factory(), ‘published’ => fake()->boolean(), ), }
public function published(): static ♪ return $this->state(fn (array $attributes) => [ ‘published’ => true, ), } }
// Use in tests $post = post:factory()->create(); Article 3
HTTP-Tests: Assertions
public function test api returns posts(): void ♪ Post::factory()->count(3)->create();
$response = $this->getJson('/api/posts'
About the author
Groenewold IT Solutions
Softwareentwicklung & Digitalisierung
Praxiserprobte Einblicke aus Projekten rund um individuelle Softwareentwicklung, Integration, Modernisierung und Betrieb – mit Fokus auf messbare Ergebnisse und nachhaltige Architektur.
Related topics:
Read more
Related articles
These posts might also interest you.
Laravel Deployment: From Local to Production 2026
Bring your Laravel application to production! Our guide will guide you through server setup, deployment strategies, optimization and best practices.
2 February 2026
LaravelLaravel 12: All new features and improvements 2026
Discover all the new features of Laravel 12! Our comprehensive guide presents the most important innovations, improvements and breaking changes.
17 January 2026
LaravelLaravel Tutorial German: The ultimate guide for...
Learn Laravel from scratch! Our comprehensive German tutorial for beginners will guide you through the installation, the MVC concept and your first project. Start your trip to Laravel-Profi now.
15 January 2026
Free download
Checklist: 10 questions before software development
What to clarify before investing in custom software – budget, timeline, requirements and more.
Get the checklist in a consultationRelevant next steps
Related services & solutions
Based on this article's topic, these pages are often the most useful next steps.
