3
我扩展了PHPUnit_Framework_TestSuite来覆盖setUp和tearDown方法,因为我需要PHPUnit在一组测试之前和之后执行一些操作。 (测试是在多个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扩展MyTestSuite'。请注意,'setUp()'和'tearDown()'方法是为了在每个* test方法之前和之后运行。也许你需要的是'setUpBeforeClass()'和'tearDownAfterClass()'。 – 2014-10-17 21:16:03
因为它们是完全不同类型的测试,我不想为了逻辑原因而把它们放在同一个类中。可悲的是,他们都需要相同的“setUpBeforeClass”和“tearDownAfterClass”。所以这就是我使用测试套件的原因。如果你看看phpunit的代码本身,https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/TestSuite.php测试套件类没有这两种方法...但是如果你看您对setUp和tearDown发表了评论:“在测试套件的测试运行之前调用的模板方法。” – holygrinder 2014-10-19 16:59:43