[英]Symfony 4 php unit test - no tests executed
在我的 symfony 4 应用程序中,我尝试从 symfony doc运行第一个单元测试。 但它返回以下消息。
// tests/Util/CalculatorTest.php
namespace App\Tests\Util;
use App\Util\Calculator;
use PHPUnit\Framework\TestCase;
public class CalculatorTest extends TestCase
{
public function testAdd()
{
$calculator = new Calculator();
$result = $calculator->add(30, 12);
// assert that your calculator added the numbers correctly!
$this->assertEquals(4, $result);
}
}
PHPUnit 5.7.27 由 Sebastian Bergmann 和贡献者编写。
时间:17 毫秒,内存:2.00MB
未执行任何测试!
当我尝试使用以下命令直接运行该测试时,它也会出现以下错误。
$ ./bin/phpunit tests/Util/CalculatorTest.php
#!/usr/bin/env php
// tests/Util/CalculatorTest.php
namespace App\Tests\Util;
use App\Util\Calculator;
use PHPUnit\Framework\TestCase;
public class CalculatorTest extends TestCase
{
public function testAdd()
{
$calculator = new Calculator();
$result = $calculator->add(30, 12);
// assert that your calculator added the numbers correctly!
$this->assertEquals(4, $result);
}
}
PHP 致命错误:未捕获的 PHPUnit\\Runner\\Exception:在“/home/username/server/tests/Util/CalculatorTest.php”中找不到类“tests/Util/CalculatorTest”。 在 /home/username/server/bin/.phpunit/phpunit-6.5/src/Runner/StandardTestSuiteLoader.php:102
任何形式的帮助将不胜感激。
我遇到了同样的问题,我的解决方案是在我的项目的根目录中添加一个 phpunit.xml 配置文件。
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.