Yii 功能测试
我试着做一些功能测试,比如在Yii的最终指南中加入一个示例 这是我在tbl_showcase.php中的固定装置:Yii 功能测试,yii,functional-testing,Yii,Functional Testing,我试着做一些功能测试,比如在Yii的最终指南中加入一个示例 这是我在tbl_showcase.php中的固定装置: return array( 'sample1'=>array( 'title'=>'Welcome', 'content'=>'A main page test', 'row_type'=>1, ), 'sample2'=>array( 'title'=>'A
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.
您可以通过显式地为ShowcaseTest类提供
name
属性来绕过它,如下所示:
public $fixtures = array('showcase'=>'Showcase');
public $name = 'Something Meaningful';
或者查看fixtures文件本身,其中定义了属性。我是Yii的初学者。关于“显式地为ShowcaseTest类指定名称属性”的更多信息,请参阅。如果可能,请显示代码示例。我会说俄语和乌克兰语。我不明白什么是“名字”财产。名称是谁的?测试基础结构取决于测试类的name属性,但是您定义的类却没有它,除非您手动分配该属性。这一财产的价值实际上似乎并不相关。Но общий смысл понятен. Гжжааааааааааааааааааааа。