TDD 只是一种思想、设计方法论,需要很多工具支持以达到敏捷的效果,基本的测试工具有,比如phpunit
清除缓存
pear clear-cache
#(更新pear)
pearupgrade-all
#安装
pearchannel-discover pear.phpunit.de
pearchannel-discover components.ez.no
pearchannel-discover pear.symfony-project.com
pearinstall --alldeps phpunit/PHPUnit
查看版本,确定是否安装正确
phpunit --version
安装其他依赖工具
curl:
打开php.ini配置,开启curl
extension=php_curl.dll
HTTP_Request2:
安装命令
pear install HTTP_Request2
PHPUnit_Selenium:
安装命令
pear install phpunit/PHPUnit_Selenium
#操作数据库必备扩展 PHPUnit_Extensions_Database_TestCase
安装命令
pear install phpunit/DbUnit
安装xdebug
调试php代码工具,此处用于生成代码覆盖率
如何安装请参考此文章
http://www.phpddt.com/php/xdebug.html
参考文档:
官网:http://phpunit.de/manual/current/en/
Phpunit安装:
http://phpunit.de/manual/current/en/installation.html
Phpunit 依赖包:
http://pear.phpunit.de/
安装错误解决:
http://blog.sina.com.cn/s/blog_46d39f4801014jsn.html
创建一个简单测试文件:LoginTest.php,内容如下
require_once'PHPUnit/Autoload.php';
class ArrayTest extends PHPUnit_Framework_TestCase
{
public function testArrayContainsAnElement()
{
// Create the Arrayfixture.
$fixture = array();
// Add an element to theArray fixture.
$fixture[] = 'Element';
// Assert that the sizeof the Array fixture is 1.
$this->assertEquals(1,sizeof($fixture));
}
}
?>
在命令行输入: phpunit LoginTest.php
Phpunit 命令参数介绍请参考其他文章
http://blog.csdn.net/chinabluexfw/article/details/7484742
参考文档:
参数介绍:
http://blog.csdn.net/chinabluexfw/article/details/7484742
phpunit 官网:
http://phpunit.de/manual/current/en/
Phpunit 默认配置文件为:phpunit.xml.
下面通过.xml 文件来介绍一下phpunit.xml标签的用法与含义
xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="/test/Web/ServiceInit.php">
<testsuites>
<testsuite name="ServiceSuite">
<directory suffix="Test.php">test/Web/Servicedirectory>
testsuite>
testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix="Service.class.php">src/Servicedirectory>
whitelist>
filter>
<logging>
<log type="coverage-html"target="test/Log/html"charset="UTF-8"yui="true"highlight="false"lowUpperBound="35"highLowerBound="70"/>
<log type="coverage-clover"target="test/Log/coverage/coverage.xml"/>
logging>
phpunit>