2013-02-17 27 views
0

I'm按照手冊「敏捷Web應用程序與農業開發和Yii1.1 PHP5」,和我不知道,爲什麼測試CRUD失敗,KO斷言測試CRUD,出自PHPUnit與誼

在正確測試'db連接'後(第4章),創建了正確的'實體AR類'實體AR類'但是此刻創建testCRUD,輸出返回是一個錯誤的斷言,如下所示:

OK ,0斷言)

只是有一個步驟,我沒有遵循手冊,並創建CDbConnection類,導致testsConnection沒問題。此外,我檢查所有更改類Test和main.php文件,並確定。

EntityTest.php

class EntityTest extends CDbTestCase 
{ 
    public function testCRUD() 
    { 
    } 
} 

Entity.php

public function testCRUD() 
    { 
    $newEntity=new Entity; 
    $newEntity->setAttributes(
     array(
       'name' => 'Test Entity 1', 
       'description' => 'Test entity number one', 
       'type_id' => 1, 
       'location_lat' => 77, 
       'location_lon' => 77, 
       'create_time' => '2013-02-16 20:36:00', 
       'create_user_id' => 1, 
       'update_time' => '0000-00-00 00:00:00', 
       'update_user_id' => 0, 
      ) 
    ); 
    $this->assertTrue($newEntity->save(false)); 

    $retrievedEntity=Entity::model()->findByPk(1); 
    $this->assertTrue($retrievedEntity instanceof Entity); 
    $this->assertEquals('Salva la Prospe',$retrievedProject->name); 
}   

乾杯。

回答

1

測試在其自己的類中運行方法,它不會在它正在測試的對象中調用測試方法。

這解釋了爲什麼它說0斷言。你的測試只是一個空的方法。

簡單地將所有的testCRUD代碼從Entity.php文件移動到EntityTest.php文件,它應該工作。

+0

謝謝Renzema,就像你說的那樣。我不知道,他在想什麼?很難相信,但我認爲在Test類中不可能直接使用處理信息數據的CRUD操作。這是一個非常有用的答案。 – 2013-02-18 21:50:24