Laravel phpUnit



当我运行时phpunit命令,它会抛出 phpunit help 中的所有信息,其中包含 Sebastian Bergmann 的 PHPUnit 3.7.21。所以我建议它应该有效,但还没有;

当我跑步时

phpunit ExampleTest.php
PHP Fatal error:  Class 'TestsTestCase' not found in C:xampp7htdocsprojectsheroestestsFeatureExampleTest.php on line 8

在Laravel中,我有"测试"文件夹

TestCase.php
<?php
namespace Tests;
use IlluminateFoundationTestingTestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
}

文件夹"功能"与

ExampleTest.php
<?php
namespace TestsFeature;
use TestsTestCase;
use IlluminateFoundationTestingRefreshDatabase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}

和文件夹"单元"

在拉拉维尔根文件夹中,我有

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

当我跑步时

vendorbinphpunit

它有效,但是如果有人解释为什么会很好

你可以使用这个

./vendor/bin/phpunit

像这样,它将从应用程序的根目录运行phpunit

首先使用此组合安装 PHP 单元

作曲家要求 --dev phpunit/phpunit

之后检查它是否已安装

./vendor/bin/phpunit --version

更多详情请访问 - https://technicalguide.net/how-to-use-phpunit-in-laravel/

相关内容

  • 没有找到相关文章

最新更新