Class 'Tests\DuskTestCase' not found in Ex

2019-08-19 04:49发布

I am trying to run Laravel Dusk tests, but when I run the test, a new Chrome tab pops up with this message.

Fatal error: Class 'Tests\DuskTestCase' not found in path-to-project\tests\Browser\ExampleTest.php on line 9

All I have done so far is run composer require --dev laravel/dusk:^1.0 and php artisan dusk:install.

This is my ExampleTest.php (exactly how Laravel set it up)

<?php

namespace Tests\Browser;

use Laravel\Dusk\Chrome;
use Tests\DuskTestCase;
use Laravel\Dusk\DuskServiceProvider;

class ExampleTest extends DuskTestCase
{
    /**
     * A basic browser test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $this->browse(function ($browser) {
            $browser->visit('/')
                ->assertSee('Laravel');
        });
    }
}

DuskTestCase.php is also just as Laravel set it up and has the namespace namespace Tests;.

I am using Laravel 5.4 and Dusk 1.0. I am running the test through PhpStorm, using the work around described here.

Anyone know why DuskTestCase can't seem to be found, even though it appears to be set up correctly? Thanks in advance.

3条回答
不美不萌又怎样
2楼-- · 2019-08-19 05:34

If composer dump-autoload does not solve problem, you can try these steps.

  1. Visit homepage in your browser and check if it renders properly. If not, then you probably have a problem with your webserver configuration (Hint: isn't your project subdirectory of document root?).
  2. You can try Laravel inbuilt server via php artisan serve. If homepage is accessible in your browser now, then you can try dusk again. In that case, remember to update your .env file to match APP_URL=http://127.0.0.1:8000, and run php artisan dusk from another cli window, cause php artisan serve needs to be running also.
查看更多
太酷不给撩
3楼-- · 2019-08-19 05:46

if you test using a phpstrom then u have set path of phpunit ...... in settings/languages & framework/php/test frameworks and use composer autoloader path and then select a path of your laravel dusk project with autoload.php file..... set file a vendor/autoload.php file in path to script...

查看更多
混吃等死
4楼-- · 2019-08-19 05:49

In composer.json:

add "Tests\\": "tests/" in

"autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/",
            "Tests\\": "tests/"
        }
    },

then, run composer dump-autoload to reload your packages.

查看更多
登录 后发表回答