22
votes

I have written an abstract test case class that is to be extended by concrete test case classes.

It extends from the PHPUnit_TestCase.

Is there a method or annotation that signals Phpunit to not execute this abstract test (but does not mark it as skipped or incomplete)?

Right now Phpunit runs the abstract test class as well and then reports an error that it can not instantiate it - which is by language: An abstract class can not be instantiated.

3
is this a duplicate of stackoverflow.com/questions/1413959/… ?James C
No, that question is about command line parameters. My question is about to have it coded in independent to commandline arguments.hakre

3 Answers

22
votes

If it is named FooTest rename it to FooTestCase.

23
votes

Just add the skip on the setUp():

protected function setUp()
{
    $this->markTestIncomplete();
}
12
votes

Assuming you want to exclude the file name TestCase.php. As in my case I use this class as an abstract to all my test classes which itself extends PHPUnit_Framework_TestCase.

Solution: add this to your phpunit.xml

<testsuites>
    <testsuite name="BLABLA">
        <directory suffix=".php">./tests</directory>
        <exclude>./tests/TestCase.php</exclude>
    </testsuite>
</testsuites>

My TestCase.php example:

<?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();
    }

//...