Console and Dusk Tests

Console Tests and Browser Tests with Dusk

$this->artisan() runs a command in the test process. The bookshop's shop:low-stock command exits with status 1 when stock needs reordering, so its test chains ->expectsTable(['Product', 'Stock'], [['PHP 8.5 Pocket Guide', 2]])->assertExitCode(1). expectsOutputToContain() and expectsQuestion() cover output and prompts.

Feature tests never run JavaScript. Laravel Dusk 1,946 8.7.0 does, by driving a real Chrome 1 through ChromeDriver. php artisan dusk:install created tests/Browser and downloaded the ChromeDriver that matched Chrome 154.0.8037.57. Dusk calls the app over HTTP, so something must serve APP_URL. Here that was php artisan serve:

tests/Browser/CatalogTest.phpPHP
$this->browse(function (Browser $browser) {
    $browser->visit('/login')
        ->assertSee('Please log in')
        ->visit('/products')
        ->assertSee('"count"');
});
Output
$ php artisan dusk
Warning: TTY mode requires /dev/tty to be read/writable.
   PASS  Tests\Browser\CatalogTest
  ✓ the login page loads in chrome                                       0.54s

A failing Dusk test saves a screenshot to tests/Browser/screenshots. Pest users can instead use pestphp/pest-plugin-browser 5.0.1, which runs browser tests through Playwright 26,280 .