打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
xampp+eclipse环境下使用phpunit

前提:xampp安装成功

1. 打开xampp的shell

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。如下图:

说明:
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 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
单元测试 PHPUnit 安装
有关PHP文档生成工具---PHPDocumentor
基于Jenkins实现php项目的自动化测试 打包和自动部署
十款PHP开发者关注的编码工具
PHP开发必备 PHP持续集成工具介绍(上)
PHP 单元测试(PHPUnit)(1)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服