【发布时间】:2014-10-21 13:18:47
【问题描述】:
我需要在每个测试方法之前运行一个方法。根据文档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)
我错过了什么吗?
【问题讨论】:
-
我从来没有用过这个,但是..
@before不是在测试前运行吗?和@after测试完成后?所以你的输出只会在测试之间输出结果? (只是随机猜测) -
phpunit 文档说:
The @before annotation can be used to specify methods that should be called before each test method in a test case class.所以我理解得很好,@before 应该在每个测试方法之前运行,而不是在测试用例类之前运行