Php 拉韦尔普尼特酒店

Php 拉韦尔普尼特酒店,php,laravel,unit-testing,composer-php,Php,Laravel,Unit Testing,Composer Php,当我跑的时候 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 v

当我跑的时候
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
vendor\bin\phpunit
在拉威尔,我有一个“测试”文件夹

TestCase.php
<?php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
}

我只需要开始单元测试

看起来您使用的是系统中全局安装的phpunit,它非常旧,并且与项目自动加载无关。您应该使用Composer在项目中安装的phpunit:

vendor/bin/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
vendor\bin\phpunit
它可以工作,但是如果有人解释为什么你可以使用它,那就太好了

/供应商/bin/phpunit


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

,如果您在没有参数的情况下运行
phpunit
?正如我在beggining中所写的,它抛出了许多由Sebastian Bergmann和贡献者编写的信息phpunit phpunit 7.1.5。用法:phpunit[options]UnitTest[UnitTest.php]phpunit[options]代码覆盖率选项:……请显示composer.json的完整内容。我在运行phpunit时也将其添加得更高。上面写着PHP致命错误:在第8行的ExampleTest.PHP中找不到类“Tests\TestCase”,如果你说我在做一些旧的东西,请解释我应该做哪些更改以适应-date@DimaRashevskiy这取决于如何安装此全局版本的phpunit。但您确实应该避免使用phpunit的全局版本,并且始终使用安装在本地项目中的版本。不同的项目可能需要不同版本的phpunit,因此使用全局安装将使测试结果不可预测,因为在不同的计算机上可能安装不同的版本。phpunit的本地安装在每个环境中都是一样的,因为它被锁定在
composer.lock
。谢谢。同样对于测试,我只使用crud进行基本crud项目。我不应该讲积垢,但我应该讲“主要逻辑”。我所有的方法都使用连接到crud的DB,因此问题是:什么是简单的主逻辑单元测试?我有一个来检查连接。另一个来自示例chekcs服务器的测试从('/')响应得到200,但在('/mypage')上不起作用,它给出500。这里可能有什么问题,还有什么其他简单的单元测试呢??