我编写了一个抽象的测试用例类,由具体的测试用例类扩展.
它从PHPUnit_TestCase扩展而来.
是否有方法或注释表明Phpunit不执行此抽象测试(但不将其标记为跳过或不完整)?
现在Phpunit也运行抽象测试类,然后报告一个错误,它无法实例化它 - 这是语言:抽象类无法实例化.
Dav*_*ess 17
如果它被命名FooTest重命名为FooTestCase.
jhv*_*ras 11
只需在setUp()上添加skip即可:
protected function setUp()
{
$this->markTestIncomplete();
}
Run Code Online (Sandbox Code Playgroud)
假设您要排除文件名TestCase.php.在我的例子中,我使用这个类作为我自己扩展的所有测试类的抽象PHPUnit_Framework_TestCase.
解决方案:将此添加到您的phpunit.xml
<testsuites>
<testsuite name="BLABLA">
<directory suffix=".php">./tests</directory>
<exclude>./tests/TestCase.php</exclude>
</testsuite>
</testsuites>
Run Code Online (Sandbox Code Playgroud)
我的TestCase.php例子:
<?php
namespace Foo\Bar\Tests;
use Mockery as M;
use PHPUnit_Framework_TestCase as PHPUnit;
/**
* Class TestCase is the Parent test class that every test class must extend from.
*/
class TestCase extends PHPUnit
{
public function __construct()
{
parent::__construct();
}
//...
Run Code Online (Sandbox Code Playgroud)