您的位置:首页 > 编程语言 > PHP开发

Yii单元测试环境配置总结

2014-01-22 00:02 239 查看
过完年打算使用Yii实施TDD开发,所以这两天研究一下环境配置问题,总的来说,还是很简单的,现总结一下

当前环境:

   Window 7

   XAMPP version 1.7.7

一、安装PHPUnit - 用于单元测试

1.按步骤安装
http://blog.csdn.net/onepasser2013/article/details/18412989
2.设置环境变量

在系统变量path中,增加php目录的路径,我的路径是C:\xampp\php

重启或打开一个新的cmd窗口

3.测试

cd website\yii\demos\blog\protected\tests
phpunit unit/posttest.php


输出结果:

PHPUnit 3.7.29 by Sebastian Bergmann.

Configuration read from F:\website\yii\demos\blog\protected\tests\phpunit.xml

Time: 105 ms, Memory: 8.00Mb

OK (1 test, 0 assertions)

phpunit安装成功!,接下来就需要安装selenium server了

二、安装selenium server - 用于功能测试

1.下载JAVA JDK
http://www.oracle.com/technetwork/java/javase/downloads/index.html
2.下载selenium server
http://docs.seleniumhq.org/download/


下载完后,将下载下来的selenium-server-standalone-x.xx.x.jar找个地方放好,我放在C:\xampp\php

3.根据教程使用pear安装
https://github.com/Element-34/php-webdriver
pear channel-discover element-34.github.com/pear
pear install -f element-34/PHPWebDriver
4.打开selenium-server-standalone-x.xx.x.jar所在目录,执行以下代码开启服务

java -jar selenium-server-standalone-x-xx-x.jar

5.Selenium Server 启动以后执行以下代码测试

cd website\yii\demos\blog\protected\tests
phpunit functional/posttest.php
6.输出结果

PHPUnit 3.7.29 by Sebastian Bergmann.

Configuration read from F:\website\yii\demos\blog\protected\tests\phpunit.xml

....

Time: 25.21 seconds, Memory: 8.50Mb

OK (4 tests, 8 assertions)

当输出以上结果时说明配置成功。

如报以下错误

Warning: include(PHPUnit_Extensions_SeleniumTestCase_Driver.php): failed to open

 stream: No such file or directory in F:\website\yii\framework\YiiBase.php on li

ne 427

Call Stack:

    0.0005     326960   1. {main}() C:\xampp\php\phpunit:0

    0.0061     696080   2. PHPUnit_TextUI_Command::main() C:\xampp\php\phpunit:4

6

    0.0062     696496   3. PHPUnit_TextUI_Command->run() C:\xampp\php\PEAR\PHPUn

it\TextUI\Command.php:129

    0.0397    4637048   4. PHPUnit_Runner_BaseTestRunner->getTest() C:\xampp\php

\PEAR\PHPUnit\TextUI\Command.php:150

    0.0421    4834848   5. ReflectionMethod->invoke() C:\xampp\php\PEAR\PHPUnit\

Runner\BaseTestRunner.php:124

    0.0421    4834864   6. PHPUnit_Extensions_SeleniumTestCase::suite() C:\xampp

\php\PEAR\PHPUnit\Runner\BaseTestRunner.php:124

    0.0457    5282576   7. PHPUnit_Extensions_SeleniumTestCase->__construct() C:

\xampp\php\PEAR\PHPUnit\Extensions\SeleniumTestCase.php:436

    0.0458    5282656   8. PHPUnit_Extensions_SeleniumTestCase->getDriver() C:\x

ampp\php\PEAR\PHPUnit\Extensions\SeleniumTestCase.php:343

    0.0460    5283456   9. YiiBase::autoload() C:\xampp\php\PEAR\PHPUnit\Extensi

ons\SeleniumTestCase.php:0

则需要再执行以下指令

pear install phpunit/PHPUnit_Selenium
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: