我尝试进行功能测试,例如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.
答案 0 :(得分:1)
你可以通过明确地将name
属性赋予ShowcaseTest类来解决它,就像那样:
public $fixtures = array('showcase'=>'Showcase');
public $name = 'Something Meaningful';
或者查看fixtures文件本身,其中定义了属性。