博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
xampp+eclipse环境下使用phpunit
阅读量:4594 次
发布时间:2019-06-09

本文共 2335 字,大约阅读时间需要 7 分钟。

前提: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. 参考资料

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

你可能感兴趣的文章
Linq to Entity 时间差作为筛选条件产生的问题
查看>>
JS常用类型事件
查看>>
Python:笔记(2)——函数与模块
查看>>
正则表达式
查看>>
raise指令触发异常实例
查看>>
sphinx的安装配置和中文分词包coreseek
查看>>
HashMap Hashtable区别
查看>>
Oracle 11i与12R在功能上有什么区别
查看>>
Hero In Maze(BFS广搜)
查看>>
操作列表
查看>>
iOS开发之Runtime使用
查看>>
导入maven项目时出现 Version of Spring Facet could not be detected. 解决方法
查看>>
nginx https ssl 设置受信任证书[原创]
查看>>
第二个项目:WC
查看>>
PowerMock注解PowerMockIgnore的使用方法
查看>>
ASP基础之内置类型及注意点
查看>>
设计模式10-装饰模式
查看>>
Beta冲刺Day4
查看>>
Android中intent启动Activity中intent.setFlags()的作用
查看>>
配置spring事务管理的几种方式(声明式事务)
查看>>