laravel fatal error for TestCase not found

前端 未结 8 1930
离开以前
离开以前 2021-02-12 13:26
http://localhost/laravel/app/tests/ExampleTest.php

if i run laravel it shows the following error

Fatal error: Class \'TestCase\' not found in D

相关标签:
8条回答
  • 2021-02-12 13:37

    Run following command in your project's root directory

    phpunit app/tests/
    

    Update:

    You can also run with the following command if phpunit is not installed on your machine. Which is also better to avoid version differences between team mates.

    vendor/bin/phpunit
    

    0 讨论(0)
  • 2021-02-12 13:37

    I got the same error but none worked,

    except for this one, this worked for me,

    I tried reinstalling and upgrading my phpunit in Laravel 5.4,

    1. modify compose.json -> find these line and change the phpunit version

      "require-dev": { "phpunit/phpunit": "~6.4" },

    2. after editing, run on your cmd,

      composer update

    3. then run

      composer dump-autoload

    4. php artisan config:clear

    5. php artisan cache:clear

    6. finally, run phpunit

    or run specific unit, phpunit --filter yourTestCaseClass

    0 讨论(0)
  • 2021-02-12 13:40

    Check if your tests directory is listed on the classmap property of your composer.json file.

    If not add it and run composer dump-autoload.

    "autoload-dev": {
        "classmap": [
            "tests",
            "database/"
        ]
    },
    
    0 讨论(0)
  • 2021-02-12 13:42

    In my case, i noticed that my root folder not contained the phpunit.xml file.

    Solve it including the following code in phpunit.xml at the root folder:

    <?xml version="1.0" encoding="UTF-8"?>
    <phpunit backupGlobals="false"
             backupStaticAttributes="false"
             bootstrap="bootstrap/autoload.php"
             colors="true"
             convertErrorsToExceptions="true"
             convertNoticesToExceptions="true"
             convertWarningsToExceptions="true"
             processIsolation="false"
             stopOnFailure="false"
             syntaxCheck="false"
    >
        <testsuites>
            <testsuite name="Application Test Suite">
                <directory>./app/tests/</directory>
            </testsuite>
        </testsuites>
    </phpunit>
    
    0 讨论(0)
  • 2021-02-12 13:48

    You haven't really given much information to go on here, but the specific problem is probably that you don't have an autoloader (thus the TestCase class that PHP is expecting isn't actually loaded. The underlying problem in turn is likely that you're trying to run ExampleTest.php directly on the terminal, whereas instead you must bootstrap a test environment correctly through Laravel and PHPUnit.

    You should find a phpunit.xml file in the root of your Laravel install. This file tells PHPUnit how to bootstrap and start executing tests for your application, so you should just be able to run phpunit on the command line in the root of your application and it should work.

    If that's not the issue, please do provide more detail for people to help with.

    0 讨论(0)
  • 2021-02-12 13:56

    I had same issue, you should run test from root folder, in your case 'http://localhost/laravel' and in terminal you just need to write phpunit, and test will be executed.

    0 讨论(0)
提交回复
热议问题