https://phpunit.de/
查找 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
由于 PHPUnit2 之后 pear 库就没有再更新过,建议采用 phar 方案
手工安装
wget https://phar.phpunit.de/phpunit.phar chmod +x phpunit.phar mv phpunit.phar /usr/local/bin/phpunit phpunit --version
测试代码
# 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)