发布时间: 2014-10-14浏览次数:7686 分类: PHP教程
PHPUnit是zend官方大力支持的测试框架,高质量的单元测试时保证项目质量的基础,能够有效的减少BUG,改善程序。
安装PHPUnit:
在php的目录下:
- pear channel-discover pear;
- pear install phpunit/PHPUnit
- <?php
- class StackTest extends PHPUnit_Framework_TestCase
- {
-
- public function testArray()
- {
- $stack = array();
- $this->assertEquals(0, count($stack));
-
- array_push($stack, 'foo');
- $this->assertEquals('foo', $stack[count($stack)-1]);
- $this->assertEquals(1, count($stack));
-
- $this->assertEquals('foo', array_pop($stack));
- $this->assertEquals(0, count($stack));
- }
-
- /**
- * @test
- */
- public function Stringlen()
- {
- $str = 'abc';
- $this->assertEquals(3, strlen($str));
- }
- }
联系客服