簡體   English   中英

Laravel phpUnit

[英]Laravel phpUnit

當我運行phpunit命令時,它會使用Sebastian Bergmann的PHPUnit 3.7.21從phpunit幫助中拋出所有信息。 所以我建議它應該起作用,但還沒有;

當我跑步時

phpunit ExampleTest.php
PHP Fatal error:  Class 'Tests\TestCase' not found in C:\xampp7\htdocs\projects\heroes\tests\Feature\ExampleTest.php on line 8

在Laravel中,我有“測試”文件夾

TestCase.php
<?php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
}

文件夾“功能”與

ExampleTest.php

<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
}

和文件夾“ Unit”

在Laravel根文件夾中

composer.json




  {
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "^1.0",
        "laravelcollective/html": "^5.4.0",
        "laravelcollective/html": "~5.0"
    },
    "require-dev": {
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ],
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

我只需要開始單元測試

看起來您正在使用全局安裝在系統中的phpunit,它非常舊,並且未與項目自動加載關聯。 您應該使用Composer安裝在項目中的phpunit:

vendor/bin/phpunit

當我跑步

vendor\bin\phpunit

它有效,但是如果有人解釋為什么會很好

你可以用這個

./vendor/bin/phpunit

這樣,它將從應用程序的根目錄運行phpunit

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM