phpunit扩展测试套件

时间:2014-10-17 18:48:58

标签: php phpunit test-suite

我扩展了PHPUnit_Framework_TestSuite来覆盖setUp和tearDown方法,因为我需要PHPUnit在一套测试之前和之后做一些操作。 (测试在多个TestCase类中。)

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
    }
}

如何在xml配置文件中告诉phpunit使用这个TestSuite类然后将testCase类绑定到它?我所能找到的只是这样的例子,似乎没有指定哪个测试套件类phpunit将使用。

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

1 个答案:

答案 0 :(得分:1)

https://phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.testsuites中有以下信息:

  

&lt; testsuites&gt;元素及其一个或多个&lt; testsuite&gt;孩子们可以   用于从测试套件和测试用例组成测试套件。

我在Magento中使用Ecomdev_PHPUnit,它确实是你想要的子类,看看它的xml:

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

所以我想通过测试套件的完整路径!

相关问题