xampp+eclipse环境下使用phpunit

前提:xampp安装成功

1. 打开xampp的shell

clip_image002

2. 查看pear是否正确

使用pear -V命令查看pear是否正确,若出现如下类似信息,则表示正确(注意,V大写)

pear -V

PEAR Version: 1.9.4

PHP Version: 5.4.6

Zend Engine Version: 2.4.0

Running on: Windows NT WN7X64-D9WWDV1 6.1 build 7601 (Windows 7 Enterprise Editi

on Service Pack 1) i586

3. 安装phpunit

如果直接升级,会发现失败,所以可以先卸载,再安装。执行如下命令:

pear uninstall pear/phpUnit

pear config-set auto_discover 1

pear channel-discover components.ez.no

pear channel-discover pear.phpunit.de

pear channel-discover pear.symfony-project.com

pear install --alldeps phpunit/PHPUnit

如果出现如下提示,不要管,在执行一次安装,直到成功为止

pear install --alldeps phpunit/PHPUnit

phpunit/PHP_Invoker requires PHP extension "pcntl"

Could not download from "http://pear.phpunit.de/get/PHPUnit-3.7.9.tgz", cannot d

ownload "phpunit/PHPUnit" (Connection to `pear.phpunit.de:80' failed: A connecti

on attempt failed because the connected party did not properly respond after a p

eriod of time, or established connection failed because connected host has faile

d to respond.

)

Error: cannot download "phpunit/PHPUnit"

Download failed

install failed

成功结果如下:

pear install --alldeps phpunit/PHPUnit

phpunit/PHP_Invoker requires PHP extension "pcntl"

downloading PHPUnit-3.7.9.tgz ...

Starting to download PHPUnit-3.7.9.tgz (116,997 bytes)

.........................done: 116,997 bytes

install ok: channel://pear.phpunit.de/PHPUnit-3.7.9

出现版本,则表示成功:

phpunit -v

PHPUnit 3.7.9 by Sebastian Bergmann.

4. 在Eclipse中设置PHPUnit

打开菜单:Run --> External Tools --> External Tools Conrigurations...,然后新建一个Program。如下图:
clip_image004

说明:
1)新建一个 Program,命名为 PHPUnit(名称可自定义)。
2)Location 中填写phpunit.bat所在的绝对路径(xampp安装目录下的php文件夹)。
3)Working Directory 中填写 ${workspace_loc}。
4)Arguments 中填写${resource_loc}(3、4步骤直接点击Variables可以直接选择)。

5. 编写测试用例

HelloUnit.php

<?php

class HelloUnit

{

public function add($a, $b)

{

return $a + $b;

}

}

?>

test.php

<?php

require_once 'PHPUnit/Framework/TestCase.php';

require_once dirname(__FILE__) . '/HelloUnit.php';//测试文件引用

class ReflectionUtilsTest extends PHPUNIT_Framework_TestCase

{

function testAdd()

{

$_helloUnit = new HelloUnit();

$this->assertEquals(3, $_helloUnit->add(1, 2));

}

}

?>

点击"Run Program"按钮,选中“PHPUnit”,控制台(Console)的输出结果如下,则表示成功:

PHPUnit 3.7.9 by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 1.75Mb

OK (1 test, 1 assertion)

6. 参考资料

PHP学习笔记 - 在Eclipse中使用PHPUnit进行单元测试 | Using PHPUnit with eclipse 

转载于:https://www.cnblogs.com/gaopeng8911/archive/2012/11/28/2792878.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值