我扩展了PHPUnit_Framework_TestSuite以覆盖setUp和tearDown方法,因为我需要在测试套件之前和之后进行一些操作。 (测试在多个TestCase类中。)
在xml配置文件中,我该如何告诉phpunit使用这个TestSuite类并将testCase类绑定到它上面?所有我找到的示例都不像明确指定phpunit应该使用哪个测试套件类。
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>
IntlFormatterTest extends MyTestSuite
。只需注意,setUp()
和tearDown()
方法是在每个测试方法之前和之后运行的。也许你需要的是setUpBeforeClass()
和tearDownAfterClass()
。 - Maciej Sz