我已经下载并安装了Codeception。我使用了以下指令:http://codeception.com/thanks在编写并运行测试之后,我得到了以下错误:
Fatal error: Call to protected method Codeception\TestCase\Test::_before() from context 'Codeception\Subscriber\Cest' in phar://C:/xampp/htdocs/codeceptiontest/codecept.phar/src/Codeception/Subscriber/Cest.php on line 11我的单元测试如下:
<?php
use \CodeGuy;
use \User; // My own class
class UserCest extends \Codeception\TestCase\Test
{
private $user;
protected function _before()
{
$this->user = new User();
}
protected function _after()
{
// Do nothing
}
// tests
public function changeUsername(CodeGuy $I)
{
$I->wantTo("change my username");
$I->amGoingTo("name my user Tim");
$this->user->setName("Tim");
$this->assertEquals($this->user->getName(), "Tim");
$this->assertTrue(true);
}
}当我的类没有扩展\Codeception\TestCase\Test时,_before()函数不会被调用,assert函数也不会工作。
欢迎提出任何建议。
发布于 2014-03-12 20:08:10
您是否尝试过公开_before()和_after()?
可悲的是,Codeception文档在许多地方都已经过时了,并且最近的一些更改打破了文档中给出的示例。
https://stackoverflow.com/questions/18639599
复制相似问题