Skip to main content

Console tests

Laravel lets you write concise tests for Artisan commands that include input and output.
This page is aligned with Laravel’s latest console testing API and also covers expectsSearch for verifying Laravel Prompts search inputs.

Introduction

Use the artisan method to run the command and chain expectations to verify it.

Success / failure assertions

You can verify the command’s success or failure by checking the exit status.

Input / output expectations

Input expectations

You can mock user interactions for question prompts and search inputs.

Output expectations

You can verify exact matches, partial matches, or table output.

Confirmation expectations

For yes/no confirmation prompts, use expectsConfirmation.

Console events

By default, CommandStarting and CommandFinished are not fired during tests. Add WithConsoleEvents to test classes that need to verify these events.
Use WithConsoleEvents only for the tests that need it to keep your general test speed high.
Last modified on July 13, 2026