【发布时间】:2011-07-15 16:48:54
【问题描述】:
我是 PHPUnit 的初学者。
这是我创建的示例测试类:
class NewTest extends PHPUnit_Framework_TestCase
{
protected $foo;
function testFirst ()
{
$this->foo = true;
$this->assertTrue($this->foo);
}
/**
* @depends testFirst
*/
function testSecond ()
{
$this->assertTrue($this->foo);
}
}
执行 testSecond 时,它会抛出一个错误,提示“Undefined property NewTest::$foo”。
为什么会这样? PHPUnit 是否在每次测试执行后清除新属性?有没有办法在测试中设置一个属性,以便在同一测试类的其他测试中可以访问它?
【问题讨论】:
标签: php testing properties phpunit