6.5. PHPUnit - Unit testing framework for PHP

https://phpunit.de/

6.5.1. 安装

6.5.1.1. 使用 pear 安装

查找 phpunit

# pear search PHPUnit
Retrieving data...0%
.Matched packages, channel pear.php.net:
=======================================
Package  Stable/(Latest) Local
PHPUnit  1.3.2 (stable)        Regression testing framework for unit tests.
PHPUnit2 2.3.6 (stable)        Regression testing framework for unit tests.			
			

安装 PHPUnit2

过程 6.1. PHPUnit2

  1. install

    pear install PHPUnit2
    					
  2. phpunit your.php

由于 PHPUnit2 之后 pear 库就没有再更新过,建议采用 phar 方案

6.5.1.2. phar 安装

手工安装

wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit
phpunit --version
			
6.5.1.3. 测试安装是否正确

测试代码

			
# cat test.php
<?php

class Test extends PHPUnit_Framework_TestCase
{
  function test1() { $this->assertTrue( 1 + 2  == 3 ); }
  function test2() { $this->assertTrue( 1 + 1  == 2 ); }
}
?>
			
			

运行测试脚本

# phpunit test.php
PHPUnit 3.7.32 by Sebastian Bergmann.

..

Time: 40 ms, Memory: 2.50Mb

OK (2 tests, 2 assertions)
			




原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值