phpunit testing woes - Class 'CTestCase' not found

I’ve installed PHPUnit and trying to run a simple test to see if there is database connects

class DbTest extends CTestCase {

    public function testConnection() {

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



when running

$ phpunit tests/unit


$ phpunit test

I get the following error:

PHP Fatal error: Class ‘CTestCase’ not found in tests/unit/DbTest.php on line 3

Not sure but in bootstrap.php when I provide wrong paths on purpose for yiit.php and config/test.php nothing happens (as in no errors come up?), is it possible that the boostrap.php in /protected/tests is not getting loaded somehow?

The importing of the CTestCase class file is certainly in the yiit file:




so you must ensure the path to this file is correctly set in the bootstrap file. Also, make sure you have a phpunit.xml config file in your tests directory that specifes the proper bootstrap.php file for bootstrapping…something like:

[xml]<phpunit bootstrap="bootstrap.php"







	&lt;browser name=&quot;Firefox&quot; browser=&quot;*firefox&quot; /&gt;



in this case, bootstrap.php and phpunit.xml should be in the same directory.

You can always put a little echo of something out in the bootstrap file and then run your test suite to ensure it is indeed being executed as you expect.

both the bootstrap.php and phpunit.xml files are in the ‘tests’ directory. I’ve commented out bootstrap.php and just added an echo to see if it loads, the echo doesn’t come up, only the same old “CTestCase” not found message. So I guess the bootstrap isn’t being loaded by phpunit. Could phpunit configuration be wrong somehow?

PHPUnit looks for phpunit.xml in the current working directory by default. It means that you should either launch phpunit from protected/tests or use --configuration (or --bootstrap) option.

Thank you! That’s exactly what it was, i need to be in the test/protected directory and

$ phpunit unit