PHPUnit 找不到“TestCase";班级

2022-01-25 00:00:00 unit-testing php phpunit

要使用项目的 PHPUnit 运行我的测试,我执行以下操作:php vendor/bin/phpunit tests/SomeClassTest.php 考虑到以下类声明,它可以正常工作:

To run my tests using the project's PHPUnit I do the following : php vendor/bin/phpunit tests/SomeClassTest.php which works fine given the following class declaration :

class SomeClassTest extends PHPUnit_Framework_TestCase {
  public function test_someMethod() {}
}

但是当我这样做时它失败了:

But it fails when I do this :

use PHPUnitFrameworkTestCase;

class SomeClassTest extends TestCase {
  public function test_someMethod() {}
}

我得到 PHP 致命错误:找不到类 'PHPUnitFrameworkTestCase'...

推荐答案

Class TestCase 从 PHPUnit 5.4 开始存在.如果你设置了 5.3 标签,你可以在 github 上看到它(寻找 ForwardCompatibility 文件夹)或者您可以比较 5.3 和 5.4 在 2.为 PHPUnit 编写测试 部分,上面写着:

Class TestCase exists since PHPUnit 5.4. You can see it on github if you set 5.3 tag (look for ForwardCompatibility folder) or you can compare doc for 5.3 and 5.4 in the 2. Writing Tests for PHPUnit section where it says:

ClassTest (大部分时间)继承自 PHPUnit_Framework_TestCase." 对于 PHPUnit 5.3

"ClassTest inherits (most of the time) from PHPUnit_Framework_TestCase." for PHPUnit 5.3

ClassTest (大部分时间)继承自 PHPUnitFrameworkTestCase." 对于 PHPUnit 5.4

"ClassTest inherits (most of the time) from PHPUnitFrameworkTestCase." for PHPUnit 5.4

相关文章