发布于 2016-01-10 03:53:42 | 308 次阅读 | 评论: 0 | 来源: PHPERZ
			PHPUnit 轻量级的PHP测试框架
PHPUnit是一个轻量级的PHP测试框架。它是在PHP5下面对JUnit3系列版本的完整移植,是xUnit测试框架家族的一员(它们都基于模式先锋Kent Beck的设计)。		
准备:下载phpunit.phar ,地址: [https://phar.phpunit.de/phpunit.phar]
配置php环境变量,我是wamp环境

phpunit.phar 将文件保存到D:\wamp\bin\php\php5.6.16\ 中

打开CMD 命令窗口<最后得到 D:\wamp\bin\php\php5.6.16\phpunit.cmd>
切换到d盘
	cd D:\wamp\bin\php\php5.6.16
	D:\wamp\bin\php\php5.6.16>echo @php "%~dp0phpunit.phar" %* > phpunit.cmd
	D:\wamp\bin\php\php5.6.16>exit
再次打开CMD
phpunit --version

到此位置,你的phpunit 环境已经安装好啦
添加test.php文件
class StackTest extends PHPUnit_Framework_TestCase
	{
	public function testPushAndPop()
   {
       $stack = array();
       $this->assertEquals(0, count($stack));
       array_push($stack, 'foo');
       $this->assertEquals('foo', $stack[count($stack)-1]);
       $this->assertEquals(1, count($stack));
       $this->assertEquals('foo', array_pop($stack));
       $this->assertEquals(0, count($stack));
   }
	}
cmd中 phpunit test.php

注意
你的php版本可能和我的不一样,但是照葫芦画瓢嘛,命令中对应你真实的版本就好啦
前言
国内composer的速度你是知道的,特别慢,所以我们就略过使用phpcomposer加载依赖,我们开始手动给项目加载依赖包
准备
下载vendor目录,里面包含常用的依赖库,如PhpUnit、PhpDocument 等等
下载地址:https://github.com/Julylovin/composer-vendor
下载vendor文件夹,放置在项目的根目录中,我的项目路径为ganx

PhpStorm 中 setting->搜索phpuni
	
]
打开前面新建的test.php文件,编辑器窗口的右上角,会有个下拉箭头,配置 Edit Configurations

点击 + 号 ,添加 phpunit 运行配置

新建在项目中新建tests文件夹,并新建phpunit test StackTest.php文件


只配置这一项,其他的不管
最后,选择你设定的 PhpUnit-dev 选项,点击绿色运行按钮(点臭虫是debug的)

到底位置,所有的配置已经完毕,尽情的享受吧~~~