Codeception中的致命错误

时间:2013-09-05 14:54:43

标签: php codeception

我已经下载并安装了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()函数,并且断言函数将不起作用。

欢迎任何建议。

1 个答案:

答案 0 :(得分:2)

您是否尝试过制作_before()和_after()?

Codeception文档在很多地方都已经过时了,最近的一些变化打破了文档中给出的例子。

相关问题