Class 'Tests\DuskTestCase' not found in ExampleTest.php

牧云@^-^@ 提交于 2020-01-06 02:45:35

问题


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.


回答1:


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.



回答2:


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...




回答3:


I had this error due to using out-of-date docs that didn't include this line:

$ php artisan dusk:install




回答4:


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.



来源:https://stackoverflow.com/questions/47946717/class-tests-dusktestcase-not-found-in-exampletest-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!