How to test Laravel applications

Published on by

How to test Laravel applications image

The Testing Laravel video course, created by Spatie, is the best way to learn how to create a quality test suite for your application. Even if you already know the basics of testing, the course contains many cool tips and tricks to sharpen your testing skills.

What is a test?

A test is a little function or script that executes some part of your application. In that script, you will also verify whether the result of that execution matches what you were expecting.

Here's a little example. Don't worry if you don't understand everything yet. We'll explain everything in the course.

it('can handle a form submission', function() {
$url = route('blogPost.create');
 
$values = [
'email' => 'john@example.com',
'name' => 'My name',
];
 
post($url, $values)->assertSuccessful();
 
assertDatabaseHas(BlogPost::class, $values);
});

The benefits of testing

The most significant benefit of having a test suite is that it will give you confidence that everything is working correctly without testing everything manually.

When coding up functionality, such as a form submission, you can write a test (like the one in the snippet above). This test can be used to verify if your form is working correctly.

There are many other benefits. In this blog post, we share more thoughts on the benefits of testing.

What you'll learn in this course

In this course, we'll teach you best practices for testing Laravel applications. You'll learn how to test from scratch. And even if you already know these basics of testing, the course contains cool tips and tricks to sharpen your testing skills.

We'll cover how to make sure your homepage works, how you can test form submissions, what the different types of tests are, and much more!

Pest is the new kid on the block in the PHP testing world that focuses on stellar developer experience. It's rapidly rising in popularity, and we believe it'll only grow in the near future. That's why we've recorded our entire course twice: first with PHPUnit, then with Pest and all the awesome features it has to offer.

You can see the entire outline on the Testing Laravel website.

A few example videos

In this sample video, we'll show how to test a simple form.

And here's one that shows you a couple of ways to test a middleware class.

Get testing tips for free

Along with the course, we've also started a newsletter called Testing Tidbits. You can subscribe to the newsletter to get daily testing tips.

Taking it even further

For those interested in not only testing, but also in creating solid web applications from scratch, we bundled Testing Laravel with our best-seller Laravel Beyond CRUD.

With both courses, you'll learn how to build, test and maintain larger-than-average Laravel applications.

When purchasing our Solid Applications Bundle you'll get a 20% discount on the grand total of these courses.

More stuff by these wizards

You might already know Spatie from their countless Laravel packages that they've created over the years.

Be sure to also check out the other products and courses by Spatie:

Eric L. Barnes photo

Eric is the creator of Laravel News and has been covering Laravel since 2012.

Filed in:
Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Larafast: Laravel SaaS Starter Kit

Larafast is a Laravel SaaS Starter Kit with ready-to-go features for Payments, Auth, Admin, Blog, SEO, and beautiful themes.

Visit Larafast: Laravel SaaS Starter Kit
Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Lucky Media logo

Lucky Media

Bespoke software solutions built for your business. We ♥ Laravel

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
Larafast: Laravel SaaS Starter Kit logo

Larafast: Laravel SaaS Starter Kit

Larafast is a Laravel SaaS Starter Kit with ready-to-go features for Payments, Auth, Admin, Blog, SEO, and beautiful themes. Available with Vue and Livewire stacks.

Larafast: Laravel SaaS Starter Kit
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector

The latest

View all →
Create a DateTime from a Timestamp With this New Method Coming to PHP 8.4 image

Create a DateTime from a Timestamp With this New Method Coming to PHP 8.4

Read article
Neovim Plugin to for Navigating Laravel and Livewire Components image

Neovim Plugin to for Navigating Laravel and Livewire Components

Read article
Laravel Herd v1.7 is out with updates to the dump UI image

Laravel Herd v1.7 is out with updates to the dump UI

Read article
Share Error Package for Laravel's New Exception Page image

Share Error Package for Laravel's New Exception Page

Read article
Sentry and Laravel announce a new partnership image

Sentry and Laravel announce a new partnership

Read article
"Fast Projects" by Larafast: Real life, ready to use Laravel based Boilerplates image

"Fast Projects" by Larafast: Real life, ready to use Laravel based Boilerplates

Read article