PHPUnit安装及入门(Unix或者Linux下)
来源:互联网 发布:知止阅读出题 编辑:程序博客网 时间:2024/06/06 01:49
系统分析与设计的课程大Project做完了,但是作为一个系统的软件流程,怎么能少了软件测试,有了软测,才是真正的软件工程。由于我们的课程项目使用的是php写的后台。而PHPUnit是一个非常好的php单元测试的工具。
首先,要来安装phpunit,在linux或者unix下,先到官网下载 https://phpunit.de/
下载下来后,命令行进入当前目录,执行如下的命令:
看到这个基本就说明安装成功了。
接下来,我们可以进行测试了。
例 1: 用 PHPUnit 测试数组操作
<?phpclass StackTest extends PHPUnit_Framework_TestCase{ public function testPushAndPop() { $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)); }}?>然后在命令行执行如下所示:
例 2: 用 @depends
标注来表达依赖关系
<?phpclass StackTest extends PHPUnit_Framework_TestCase{ public function testEmpty() { $stack = array(); $this->assertEmpty($stack); return $stack; } /** * @depends testEmpty */ public function testPush(array $stack) { array_push($stack, 'foo'); $this->assertEquals('foo', $stack[count($stack)-1]); $this->assertNotEmpty($stack); return $stack; } /** * @depends testPush */ public function testPop(array $stack) { $this->assertEquals('foo', array_pop($stack)); $this->assertEmpty($stack); }}?>然后在命令行执行如下所示:
例 3: 利用测试之间的依赖关系
<?phpclass DependencyFailureTest extends PHPUnit_Framework_TestCase{ public function testOne() { $this->assertTrue(FALSE); } /** * @depends testOne */ public function testTwo() { }}?>
命令后运行结果如下所示:
phpunit --verbose DependencyFailureTest
PHPUnit 4.7.0 by Sebastian Bergmann and contributors.FSTime: 0 seconds, Memory: 5.00MbThere was 1 failure:1) DependencyFailureTest::testOneFailed asserting that false is true./home/sb/DependencyFailureTest.php:6There was 1 skipped test:1) DependencyFailureTest::testTwoThis test depends on "DependencyFailureTest::testOne" to pass.FAILURES!Tests: 1, Assertions: 1, Failures: 1, Skipped: 1.
0 0
- PHPUnit安装及入门(Unix或者Linux下)
- windows下phpunit安装及测试
- PHPUnit介绍及安装
- Windows下PHPUnit安装
- Windows下PHPUnit安装
- windows下phpunit安装
- WAMP下安装phpunit
- centos下安装PHPUnit
- Mac下安装phpunit
- windows下phpunit安装
- windows下安装PHPunit
- linux安装phpunit&phpdoc
- centos linux安装PHPUnit 配置PHPUnit (深入浅出PHPUnit 1)
- 在Unix和Linux下安装JDK及环境设置
- vsFTPD在Unix/Linux下的安装及配置
- 在windows下安装phpunit
- xampp下安装phpunit小记
- wamp下phpunit亲自安装
- STL map使用方法详解
- codeforces #309 div2
- 拆掉思维里的墙——有感
- 黑马程序员--c语言数据类型总结
- Objective-C 快速入门--基础(一)
- PHPUnit安装及入门(Unix或者Linux下)
- 摧毁自己
- C++/VC++ 命名及其他规范
- 大型网站架构体系的演变
- JFrame 与 Frame 的区别之一
- Count Complete Tree Nodes算法详解
- ios周刊第五期
- 题目1192:回文字符串
- linux gdb调试非常有用的命令,附加案例