我需要在每个测试方法之前运行一个方法。根据文档https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.before,我做了一点测试:
/**
* @before
*/
public function setupSomeFixtures()
{
echo "setupSomeFixtures\n";
}
/**
* @after
*/
public function tearDownSomeFixtures()
{
echo "tearDownSomeFixtures\n";
}
public function testTruc()
{
echo "un test\n";
}
输出:
PHPUnit 3.7.21 by Sebastian Bergmann.
Configuration read from <root>\phpunit.xml
.un test
Time: 5 seconds, Memory: 14.25Mb
OK (1 test, 0 assertions)
我错过了什么吗?
答案 0 :(得分:1)
Before
注释是在phpunit版本3.8中引入的,因此在3.7中不起作用。
这是我的输出:
PHPUnit 4.2.6 by Sebastian Bergmann.
Configuration read from /<omissis>/app/phpunit.xml.dist
The Xdebug extension is not loaded. No code coverage will be generated.
.setupSomeFixtures
tearDownSomeFixtures
.setupSomeFixtures
tearDownSomeFixtures
.setupSomeFixtures
tearDownSomeFixtures
IsetupSomeFixtures
tearDownSomeFixtures
.setupSomeFixtures
un test
tearDownSomeFixtures
Time: 451 ms, Memory: 23.00Mb
所以升级到phpunit 3.8或主要