Everything We Know about Pest 3

Published on by

Everything We Know about Pest 3 image

Nuno Maduro was the opening speaker at Laracon US 2024 on Tuesday, unveiling impressive new features for the upcoming Pest v3.0. Pest continues to grow in popularity, being downloaded over 18 million times and is the default testing framework in Laravel as of V11.

Pest v3 takes another important leap forward with three impressive features coming to Pest 3:

  • Task management
  • Architecture Presets
  • Mutation Testing

Let's look at each of these features shared at Laracon US in more detail:

Task Management

Task management lets you track things like assignee, issue number, pull request number, and notes, directly on a test. Tracking tasks allows you to keep a history of work that will always be availabe in your test:

test('some test 1', function () {
// ...
})->todo(assignee: 'paulredmond', issue: 13);
 
it('returns a successful response', function () {
$response = $this->get('/');
 
$response->assertStatus(200);
})->todo(
assignee:'paulredmond',
issue:11,
pr:1,
note:'Need to assert the response body.'
);
 
// Eric is a closer ☕️
test('drives always go in the fairway', function () {
// ...
})->done(assignee: 'ericlbarnes', issue: 13);

From the command line, you can filter tests by assignee or issue:

$ pest --issue=11
$ pest --assignee=paulredmond --pr=1
$ pest --assignee=ericlbarnes
$ pest --issue=13
$ pest --notes # returns tests with notes

Architecture Presets

Architecture presets are a way to quickly use the same architecture rules across multiple projects, and leverage popular presets like rules for Laravel, PHP, a strict PHP preset, or a relaxed preset. These will create more consistency in your code because they'll prevent you from doing things like leaving debug functions like phpinfo(), dd(), etc.

You can use these presets using the arch()->preset() method:

// Ensures PHP functions like die(), phpinfo(), etc. are not used
arch()->preset()->php();
 
// Ensures functions like eval(), md5(), etc. are not used.
arch()->preset()->security();
 
// Preset to validate things like resourceful controller methods,
// enum organization, controller files have a `Controller` suffix, etc.
arch()->preset()->laravel();
 
// Preset to ensure classes are final, strict typing, etc.
arch()->preset()->strict();
 
// Preset to ensure strict types are not used, no final, no private methods.
arch()->preset()->relaxed();

Presets speed up development because most rules you'd expect are already defined for you. Here's an example of the security preset failing because of the use of md5():

Here's an example of using the Strict preset, demonstrating a class that is not using the final keyword:

Mutation Testing

When mutation testing ships with Pest v3, it's going to blow your mind. Mark my words, when you run mutation tests on your codebase, this feature is going to make you cry, and then you won't be able to live without it.

Even if your test suite reports 100% coverage, mutation testing will help you find gaps in your tests. It does so by removing code from your implementation, swapping logic around, and poking holes in your code to try to make your tests fail.

Backwards Compatibility

Near the end of his talk, Nuno mentioned that Pest 2 users will be able to upgrade without any backward compatibility breaks. Users should be able to update the package to require v3 and update composer dependencies. This is huge because fixing compatibility breaks in your testing tool can be painful, especially if you have a lot of tests.

The future of Pest is bright with productive tools that level up your testing through mutations, make your application architecture more consistent, and help keep track of assignees and issues directly in your tests.

Which feature are you most excited about? Let us know on your favorite social media app!

Paul Redmond photo

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

Filed in:
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
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 →
Ben Holmen: Building Connections and Friendships through Pair Programming with Strangers image

Ben Holmen: Building Connections and Friendships through Pair Programming with Strangers

Read article
Laravel Herd Adds Forge Integration, Dump Updates, and More in v1.11 image

Laravel Herd Adds Forge Integration, Dump Updates, and More in v1.11

Read article
Chaperone, Defer, Cache::flexible, and more are now available in Laravel 11.23 image

Chaperone, Defer, Cache::flexible, and more are now available in Laravel 11.23

Read article
UnoPim is a Product Information Management System Built With Laravel image

UnoPim is a Product Information Management System Built With Laravel

Read article
Pest 3 is released! image

Pest 3 is released!

Read article
Build Your Multi-Tenant SaaS App in Days with SaaSykit Tenancy image

Build Your Multi-Tenant SaaS App in Days with SaaSykit Tenancy

Read article