【问题标题】:Yii functional testingYii 功能测试
【发布时间】:2012-02-25 10:55:13
【问题描述】:

我尝试进行功能测试,例如在 The Definitive Guide to Yii 中。

这是我在 tbl_showcase.php 中的固定装置:

return array(
    'sample1'=>array(
        'title'=>'Welcome',
        'content'=>'A main page test',
        'row_type'=>1,
    ),
    'sample2'=>array(
        'title'=>'About',
        'content'=>'An about page test',
        'row_type'=>2,
    ),
);

这是我的测试课:

class ShowcaseTest extends WebTestCase
{
    public $fixtures = array('showcase'=>'Showcase');

    public function testIndex()
    {
        $this->open('/');

        $this->assertTextPresent($this->showcase['sample1']['title']);
        $this->assertTextPresent('Welcome');

        $this->assertTextPresent($this->showcase['sample1']['content']);
        $this->assertTextPresent('A main page test');
    }
}

我开始测试

phpunit functional/ShowcaseTest.php

然后得到下一个错误:

Time: 8 seconds, Memory: 6.25Mb

There was 1 error:

1) ShowcaseTest::testIndex
Exception: Unknown property 'name' for class 'ShowcaseTest'.

/home/myfolder/web/yii/framework/test/CWebTestCase.php:48

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.

【问题讨论】:

    标签: yii functional-testing


    【解决方案1】:

    您可以通过将 name 属性显式赋予 ShowcaseTest 类来绕过它,如下所示:

    public $fixtures = array('showcase'=>'Showcase');
    public $name = 'Something Meaningful';
    

    或者查看fixtures文件本身,其中定义了属性。

    【讨论】:

    • 我是 Yii 的初学者。请更多关于“明确地将 name 属性赋予 ShowcaseTest 类”。如果可能,请显示代码示例。我可以说俄语和乌克兰语。
    • 我不明白什么是“名称”属性。谁的名字?
    • 测试基础结构依赖于测试类的 name 属性,但是您以某种方式定义的类没有它 - 除非您手动分配该属性。这个属性的值实际上是不相关的,看起来。
    • Я понял не все。 Но общий смысл понятен。 Где можно детально прочитать об этом?
    • 请用英文写,否则大多数人无法理解或回应。
    猜你喜欢
    • 2013-03-05
    • 2013-08-31
    • 2014-06-09
    • 2014-07-12
    • 2012-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    相关资源
    最近更新 更多