简单的了解一下PHPUnit单元测试框架,由于螃蟹在win下使用的xamp环境,直接使用xamp/php目录里面的pear.bat来安装PHPUnit,经过一番折腾,终于是安装上了PHPUnit4.0.17。然后搜了一些教程,发现没有一个能用的,大多数都是版本不一样,测试就报错,最后在官网发现中文教程,测试通过。
编写phpunit_test1.php
<?php
class calculator {
function add($p1, $p2) {
return $p1 + $p2;
}
}
class calculatorTest extends PHPUnit_Framework_TestCase {
public function testCanBeNegated(){
$calc = new calculator();
print_r($calc->add(1,20));
}
}
?>
运行结果:
PHPUnit 4.0.17 by Sebastian Bergmann.
You have installed PHPUnit via PEAR. This installation method is no longer
supported and http://pear.phpunit.de/ will be shut down no later than
December, 31 2014.
Please read http://phpunit.de/manual/current/en/installation.html and
learn how to use PHPUnit from a PHAR or install it via Composer.
.21
Time: 67 ms, Memory: 3.75Mb
OK (1 test, 0 assertions)
来源:oschina
链接:https://my.oschina.net/u/926989/blog/302444