Search code examples
phpphpunittest-suite

phpunit extend test suite


I extended PHPUnit_Framework_TestSuite to overwrite the setUp and tearDown methode because I need PHPUnit to do some operation before and after a suite of test. (the test are in multiple TestCase class.)

class MyTestSuite extends PHPUnit_Framework_TestSuite {

    protected function setUp()
    {
        //do some stuff before all tests are run
    }

    protected function tearDown()
    {
        //do some stuff after all tests are run
    }
}

How in a xml config file do I tell phpunit to use this TestSuite class and then bound the testCase class to it? All I can find are example like this which doesnt seem like specify which test suite class phpunit shall use.

<phpunit>
  <testsuites>
    <testsuite name="money">
      <file>tests/IntlFormatterTest.php</file>
      <file>tests/MoneyTest.php</file>
      <file>tests/CurrencyTest.php</file>
    </testsuite>
  </testsuites>
</phpunit>

Solution

  • In https://phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.testsuites there is this information:

    The <testsuites> element and its one or more <testsuite> children can be used to compose a test suite out of test suites and test cases.

    I use Ecomdev_PHPUnit in Magento, which does subclass like you want, look at its xml:

    <testsuite name="Magento Test Suite">
         <file>app/code/community/EcomDev/PHPUnit/Test/Suite.php</file>
    </testsuite>
    

    So just pass the test suite complete path I guess!