2012-02-25 153 views
0

我嘗試做功能測試,比如進入Yii權威指南。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. 

回答

1

您可以通過明確賦予name屬性ShowcaseTest類,這樣繞過它:

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

或可考慮夾具文件本身,其屬性定義。

+0

我是Yii的初學者。請稍微瞭解一下「明確給Namecase屬性添加ShowcaseTest類」。請顯示代碼示例,如果可能的話。我可以對俄羅斯和烏克蘭說話。 – starter 2012-02-25 13:00:45

+0

我不明白什麼是「名稱」屬性。這是誰的名字? – starter 2012-02-25 13:07:38

+0

測試基礎設施取決於測試類的名稱屬性,但您定義的類沒有它 - 除非您手動分配屬性。看起來,這個屬性的價值實際上並不相關。 – raina77ow 2012-02-25 13:12:21