Note that there are some explanatory texts on larger screens.

plurals
  1. PONon-testable base class extending PHPUnit_Framework_TestCase
    text
    copied!<h2>Summary</h2> <p>How can I create a base class that extends PHPUnit_Framework_TestCase and use that for subclassing actual test cases, without having the base class itself tested by PHPUnit?</p> <h2>Further explanation</h2> <p>I have a series of related test cases for which I have created a base class that contains some common tests to be inherited by all test cases:</p> <pre><code>BaseClass_TestCase.php: class BaseClass_TestCase extends PHPUnit_Framework_TestCase { function test_common() { // Test that should be run for all derived test cases } } MyTestCase1Test.php: include 'BaseClass_TestCase.php'; class MyTestCase1 extends BaseClass_TestCase { function setUp() { // Setting up } function test_this() { // Test particular to MyTestCase1 } } MyTestCase2Test.php: include 'BaseClass_TestCase.php'; class MyTestCase2 extends BaseClass_TestCase { function setUp() { // Setting up } function test_this() { // Test particular to MyTestCase2 } } </code></pre> <p>My problem is that when I try to run all the tests in the folder, it fails (without output).</p> <p>Trying to debug I've found that the problem lies with the base class being itself a subclass of PHPUnit_Framework_TestCase and therefore PHPUnit will also try to run its tests. (Until then I naively thought that only classes defined inside actual test files - filenames ending in Test.php - would be tested.)</p> <p>Running the base class as a test case out of context doesn't work due to details in my specific implementation.</p> <p>How can I avoid the base class being tested, and only test the derived classes?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload