A Roundup of Laravel Testing Resources and Packages

Published on by

A Roundup of Laravel Testing Resources and Packages image

Testing code is one of the more challenging parts of programming, but luckily Laravel and some other tools are making it easier than ever. Research has even shown implementing a Test-Driven Development (TDD) approach can significantly reduce the number of bugs that make it to production. Testing provides many other benefits, like the freedom to refactor large parts of a system without (as much) fear of breaking things.

Everybody has a testing environment. Some people are lucky enough enough to have a totally separate environment to run production in.

— Papa Devops (@stahnma) August 21, 2015

With all of the benefits of testing, it’s still challenging to continually test applications. If you are looking to start learning how to test Laravel applications or you want to expand your skills here is a list of great resources to help you:

The Official Documentation

](https://laravel.com/docs/master/testing)

The official Laravel documentation is arguably the most complete testing guide that ships with a PHP framework. Not only does the guide itself make it very easy to start testing Laravel applications, but the framework itself also provides essential tools that take away the excuses of not testing. The most important features to make testing easier—that ship with Laravel—include database migrations for testing, factories, and mocking/fakes.

This first resource is obvious, but those new to Laravel and testing applications, stop by the documentation first. As a companion to the documentation, watch the Laracasts video Laravel From Scratch: Testing 101 for an overview of testing Laravel.

Laravel Dusk

](https://github.com/laravel/dusk)

Laravel Dusk is a browser testing package that works with >= Laravel 5.4. The Dusk documentation is part of the official Laravel documentation, but it’s worth mentioning separately because it is a recent addition to the Laravel testing tools. Dusk doesn’t require Selenium but uses the standalone ChromeDriver—which ships with the package.

Dusk allows you to test dynamic JavaScript applications with convenient browser abstractions and PHPUnit assertions. Before Laravel 5.4 full browser testing automation wasn’t possible without third party packages. This is another example of the Laravel framework facilitating testing and making it convenient for developers to get started.

The Orchestral Testbench Component

](https://github.com/orchestral/testbench)

The Orchestral Testbench package is a testing helper for Laravel package development. According to the readme file, the Orchestral Testbench package:

…is a simple package that has been designed to help you write tests for your Laravel package, especially when there is routing involved.

The Laracasts Laravel Behat Extension

](https://github.com/laracasts/Behat-Laravel-Extension)

Behat is the defacto tool for Behavior-Driven Development (BDD) in the PHP community, and this package can help you get started with Behat and Laravel quickly. Before Laravel Dusk was available, full browser testing automation was only possible with third party packages and tools.

Although Dusk is now available, Behat might be a tool you prefer for acceptance testing if you prefer the BDD flavor of testing with Cucumber. Laracasts provides a lesson on using Behat,Laravel 5 and Behat: BFFs, which will help you get started with Behat 3 and Laravel 5.

phpspec

](http://www.phpspec.net/en/stable/)

phpspec is a tool for writing BDD Specifications in PHP. The interesting thing about phpspec is how it guides you through small steps in writing test specifications, then making them pass. Learning phpspec can open your mind to a new way of testing.

You can learn how to get started with the phpspec manual. Laracasts has an introduction video to compliment the documentation. phpspec is a great tool for testing any PHP project, including Laravel packages.

phpspec Laravel Extension

](https://github.com/BenConstable/phpspec-laravel)

phpspec Laravel Extension helps you test Laravel applications with phpspec:

This extension provides you with a bootstrapped Laravel environment when writing your phpspec tests.

Learning phpspec is a prerequisite for using this package.

Let’s Build a Forum with Laravel and TDD

](https://laracasts.com/series/lets-build-a-forum-with-laravel)

The Build a Forum with Laravel and TDD series is only available to subscribers, but a the time of this writing there are 58 lessons on building a forum with Laravel and Test-Driven Development. This is one of the most complete tutorials on testing with Laravel and TDD. Even if you exhaust the generous number of free resources first, this is a great way to learn more about TDD with Laravel.

Test-Driven Laravel

](https://adamwathan.me/test-driven-laravel/)

Test-Driven Laravel is a video series by Adam Wathan which provides a thorough look into testing Laravel applications. This course is not free, but as of this writing, you could still get early access. The course has many hours of courses with more still being added.

Adam Wathan initially gave a presentation on Test-Driven Laravel at ZendCon and then condensed his talk into a screencast you can watch online. We’ve also reviewed this course on Laravel News.

Spatie Laravel Packages

](https://github.com/spatie?utf8=%E2%9C%93&q=laravel&type=source&language=php)

Spatie provides many Laravel packages, and they continue to ship new packages to the community. The packages contain a wealth of testing source code and are a good reference to help you learn how to test Laravel packages. Some packages have a dependency on the aforementioned Orchestral Testbench, providing you with some examples of using Testbench in action.

Spatie packages also have Continuous Integration with Travis CI (laravel-backup example). The murze.be blog provides Laravel tips and tricks on package development and new package announcements being released by Spatie.

The Ruby on Rails Tutorial Book

](https://www.railstutorial.org/book)

This resource is a bit of a wildcard. While not PHP or Laravel related, this free online book is chock-full of real-world testing examples you can apply to your projects. It starts picking up testing features in Chapter 3.3.

Even if you don’t care about Ruby or Rails, you will be hard-pressed to find better testing material on how to write web application tests, including the theory behind what to test and how to test it. You can follow along or just read through the material to get some great testing insight and inspiration.

Test Driven Development: By Example

](http://amzn.to/2t07vON)

Test Driven Development: By Example is considered by many a classic text on TDD. While the examples are not written in PHP, the book covers an expansive list of TDD patterns and practices and will provide beginners a good background on TDD with some practical examples.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

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

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

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

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
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant 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
Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate logo

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate

Build your SaaS application in hours. Out-of-the-box multi-tenancy and seamless Stripe integration. Supports subscriptions and one-time purchases, allowing you to focus on building and creating without repetitive setup tasks.

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate
Rector logo

Rector

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

Rector
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Asymmetric Property Visibility in PHP 8.4 image

Asymmetric Property Visibility in PHP 8.4

Read article
Access Laravel Pulse Data as a JSON API image

Access Laravel Pulse Data as a JSON API

Read article
Laravel Forge adds Statamic Integration image

Laravel Forge adds Statamic Integration

Read article
Transform Data into Type-safe DTOs with this PHP Package image

Transform Data into Type-safe DTOs with this PHP Package

Read article
PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell image

PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell

Read article
Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3 image

Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3

Read article