简体   繁体   English

Codeception单元测试[RuntimeException]调用未定义的方法UnitTester :: haveRecord

[英]Codeception Unit testing [RuntimeException] Call to undefined method UnitTester::haveRecord

I am new in Codeception trying to run a sample unit test in my Laravel framework but getting the following error: 我是Codeception的新手,试图在我的Laravel框架中运行示例单元测试,但收到以下错误:

[RuntimeException] Call to undefined method UnitTester::haveRecord

And following code I have tried to run using Codeception: 以下代码我尝试使用Codeception运行:

 <?php namespace Article;
 use App\Article;
 use Faker\Factory as Faker;
 use Carbon\Carbon;
 class SaveTest extends \Codeception\Test\Unit
{
/**
 * @var \UnitTester
 */
protected $tester;

protected function _before()
{
}

protected function _after()
{
}

// tests
public function testSomeFeature()
{
    $faker= Faker::create('App/Article');

        $title = $faker->sentence;
        $content = implode($faker->paragraphs(5));
        $created_at = Carbon::now();
        $updated_at = Carbon::now();


        $this->tester->haveRecord( 'Article',   ['title' => $title, 'content' => $content,'created_at' => $created_at,'updated_at' => $updated_at]);


         $this->tester->seeRecord('articles',['title' => $title,'content' => $content,'created_at' => $created_at,'updated_at' => $updated_at]);




}
}

Could please help me out of this error? 可以帮我解决这个错误吗? Thanks in advance. 提前致谢。

The issue resolved after I have enabled Laravel5 module in unit.suite.yml 在unit.suite.yml中启用Laravel5模块后,问题解决了

The unit.suite.yml file format with Laravel5 module: Laravel5模块的unit.suite.yml文件格式:

actor: UnitTester
modules:
 enabled:
    - Asserts
    - Laravel5:
        part: ORM
    - \Helper\Unit

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Codeception RuntimeException 调用未定义的方法 FunctionalTester::amOnPage - Codeception RuntimeException Call to undefined method FunctionalTester::amOnPage 调用Laravel 5 + Codeception功能测试中未定义的方法Session :: has() - Call to undefined method Session::has() in Laravel 5 + Codeception functional testing 对未定义方法 assertEquals 的代码接收调用 - Codeception call to undefined method assertEquals Codeception错误:调用未定义的方法Exception :: getStatusCode() - Codeception Error : Call to undefined method Exception::getStatusCode() 使用 Codeception 进行单元测试:解析错误 - Unit testing with Codeception: parsing error Laravel 包单元测试在配置文件中的辅助函数失败(调用未定义的方法 base_path()) - Laravel package unit testing failing for helper function in config file (call to undefined method base_path()) 使用代码进行Laravel测试:单元测试模型的save()方法不会持久化 - Laravel testing with with codeception: unit test model's save() method doesn't persist 在 Laravel 8 的单元测试中调用未定义的方法 Tests\\Unit\\TopPageTest::get() - Call to undefined method Tests\Unit\TopPageTest::get() in Unit test in Laravel 8 尝试运行单元测试时的代码接收“未定义的变量输出” - Codeception 'Undefined variable output' when trying to run a unit test Laravel 5测试环境未在Codeception单元测试中设置 - Laravel 5 testing environment not getting set in Codeception unit tests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM