Writing your first Pest test in Laravel

Writing your first Pest test in Laravel

2 h Calm

Start
Automatically translated · View original (Dutch)

Better code with fewer bugs starts with tests. Write and run your very first Pest test in Laravel.

Tests are every developer's safety net. They catch mistakes before your users do. Pest is a testing framework for PHP, built on top of PHPUnit but with a simpler, more enjoyable API. In Laravel it is set up so that you can have your first test running within an hour.

You install Pest via Composer, create a test file, and write a short test that checks whether your welcome page loads. Then you run it from the terminal. Green means passed, red means there is work to be done. After that first green bar, you will never look at your code the same way again.

Install Pest in your Laravel project via Composer with composer require pestphp/pest --dev.

Create a test file in the tests folder and write a simple test that checks whether your welcome page loads with a 200 status.

Suggestion: Use it('loads the welcome page', ...) with an assertStatus(200).

Run your test from the terminal with ./vendor/bin/pest. Green means passed, red means there is something to fix.

Related playbooks

📚
Related

Explore the folder structure of a Laravel project

Know exactly where everything lives in Laravel. Walk through the structure folder by folder and understand how a project is built.

📚
Related

Take your first steps with Laravel

Dive into web development with one of the most popular PHP frameworks. Install Laravel and build your very first route.

📚
Related

Learn API Authentication with Laravel Sanctum

Secure your APIs like a pro. Learn how to install Laravel Sanctum, manage tokens, and protect your routes, step by step.

📚
Related

Build your own GPS tracker with a Raspberry Pi and Laravel

A fun tinkering project for anyone who loves tech and code: a GPS tracker built from a Raspberry Pi and Laravel.

📚
Related

Understanding 3D Printing Before You Start

Get a quick grasp of how 3D printing works: the techniques, the applications, the materials, and the costs to get started.

📚
Related

Fighting pests with nematodes: natural and chemical-free

Tiny soil worms that take out harmful insects. An eco-friendly alternative to pesticides, here's how to do it.

📚
Related

Learn the basics of web development in seven days

Go from your first HTML tag to your own website in a week. HTML, CSS and JavaScript in manageable daily steps.

📚
Related

Prepare for your motorcycle theory exam online

Passing your motorcycle theory starts with studying smart. Use online practice exams and a consistent method to walk into the exam room with confidence.

📚
Related

Choose a driving school and plan your first lesson

The first step towards your driving licence is choosing a good driving school. Compare, choose wisely, and book your first lesson right away.

📚
Related

Understanding SEO as a beginner, this is how visibility works

Why does one site find you and another doesn't? Learn the basics of SEO and the principles it's built on.

by PlayTryBe team