Php单元测试

在Yii上试用PHP单元测试,但是报错


PHP Warning: require_once(PHPUnit/Extensions/SeleniumTestCase.php): failed to open stream: No such file or directory in /var/www/html/yii-1.1.13.e9e4a0/framework/test/CWebTestCase.php on line 12

求指教~

require_once()报错的问题已经解决,看http://www.phpunit.de/manual/current/en/phpunit-book.html phpunit的文档中Chapter 3. Installing PHPUnit这一章节,先看下看头部分的Note,确定环境没问题,再到本章节的Optional packages,部分,下载DbUnit、PHP_Invoker、PHPUnit_Selenium、

PHPUnit_Story、PHPUnit_SkeletonGenerator等可选包,应该就可以解决require_once包含一些文件发生找不到文件的错误,你可以执行ls /usr/share/pear/PHPUnit/命令查询有那些目录,我的有

Autoload.php Extensions Framework Runner TextUI Util。

另外在Yii框架中使用phpunit发现当我执行phpunit unit/BBCodeTest.php命令时,能正常执行,而执行phpunit webTest/protected/tests/unit/BBCodeTest.php 命令时报错!提示找不到CTestCase类,这是Yii框架自带的类,在/var/www/html/yii-1.1.13.e9e4a0/framework/test/路径里,webTest与yii-1.1.13.e9e4a0是在同一目录下!当我执行phpunit BBCodeTest.php时,也报错,同样是找不到

CTestCase,难道测试文件里包含了其他类phpunit命令必须在测试文件的上一个目录执行!!最后发现原来是这个东东的问题

Configuration read from /var/www/html/webTest/protected/tests/phpunit.xml

PHPUnit默认会读取当前目录下的phpunit.xml配置文件,在里面包含了所需要用到的类(非PHPUnit的类,自己设定的),问题大概自己解决了~