正在学习yii框架,在编写php代码的时候,要用到单元测试。以前只据说单元测试,没怎么了解过,此次要用到了。在yii框架中使用phpUnit进行单元测试真的很方便。从Yii1.1版本起,Yii已经紧密结合phpUnit和selenium remote control测试框架。 php
这是yiic webapp 自动生成的 /protected/tests/目录,,咱们将测试文件主要放到这个目录:fixtures , functional,unit。 html
一. 安装PHPUnit java
(1)在命令行: web
$>sudo pear channel-discover pear.phpunit.de
$>sudo pear install phpunit/PHPUnit
这是在opensuse13.1终端上所获得实验步骤,可能您的配置略有不一样。详细安装过程请参考http://phpunit.de/manual/3.7/en/installation.html
(2)opensuse13.1 Yast2 shell
打开yast2 出入phpunit勾选相应的选项。而后也能够成功安装。 app
二. 安装selenium 框架
除了phpunit,selem remote control server 为是了运行测试功能所须要的,安装selenium很是简单。 yii
[1] . 从http://code.google.com/p/selenium/downloads/list 下载 Selenium RC 的zip文件 curl
[2] .解压下载的zip文件到你的系统中。 webapp
运行这个服务时也很简单:
在shell下:
$>java -jar selenium-server-standalone-2.37.0.jar
至此phpUnit安装已经搞定,用上面的方法开启 Selenium 服务
可是当我在 /protected/tests/> phpunit functional/SiteTest.php 时产生了错误。
Warning: include(): Failed opening ‘PHPUnit_Extensions_SeleniumTestCase_Driver.php
查找资料之后在shell下面输入:
pear upgrade -f phpunit/phpunit_selenium
php须要开启 curl
而后重新测试看到了以下的结果