Could you help me about the TDD case?

I’m sure my config file is correct and webapp is running well. I just want to try unit test, so I made a test case like this:


class DbTest extends CTestCase


  function testConnection(){

    $this->assertNotEquals(NULL, Yii::app()->db);




run: phpunit unit/DbTest

but result is:

There was 1 error:

1) DbTest::testConnection

CDbException: CDbConnection failed to open the DB connection.








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

Where I should go, can anybody give me some hints? thanks a lot!

check the db connection on the protected/config/console.php, make sure db is set under component, example

return array(


	'name'=>'My Console Application',









Thank you for your time, but the problem still there, even I re-configured the console.php rely on my connection situation:(

Resolved just change test config from ‘localhost’ into ‘’ in connection section.Don’t know why main.php localhost works but test.php not.

i think the right config file is config/test.php

whoops you are right, thanks!