zoukankan      html  css  js  c++  java
  • ubuntu下安装和使用phpunit实例

    执行 pear 命令,查看是否安装了pear
    如果没有安装,则去安装
    sudo apt-get install php-pear

    获取phpunit:
    pear config-set auto_discover 1
    pear install pear.phpunit.de/PHPUnit

    如果失败, 先更新
    pear upgrade-all
    pear install pear.phpunit.de/PHPUnit

    在/tmp/pear/download 下会找到文件包 PHPUnit-3.7.10.tgz
    解压到要使用的地方

    创建测试文件 test.php

     1 <?php
     2     error_reporting(-1);
     3     require(‘./PHPUnit/Autoload.php’);
     4     class ArrayTest extends PHPUnit_Framework_TestCase {
     5         public function testNewArrayIsEmpty(){
     6             $fixture = array();
     7             $this->assertEquals(0, count($fixture));
     8         }
     9 
    10         public function testArrayContainsAnElement(){
    11             $fixture = array();
    12             $fixture[] = ‘Element’;
    13             $this->assertEquals(1, sizeof($fixture));
    14         }
    15     }
    16 ?>   

    执行:
    phpunit test.php

    返回:
    PHPUnit 3.7.10 by Sebastian Bergmann.

    ..

    Time: 0 seconds, Memory: 2.75Mb

    OK (2 tests, 2 assertions)

    修改
    $this->assertEquals(0, count($fixture));

    $this->assertEquals(0, count($fixture));

    在执行:
    phpunit test.php

    返回:
    PHPUnit 3.7.10 by Sebastian Bergmann.

    F.

    Time: 1 second, Memory: 2.75Mb

    There was 1 failure:

    1) ArrayTest::testNewArrayIsEmpty
    Failed asserting that 0 matches expected 1.

    /var/www/test.php:7

    FAILURES!
    Tests: 2, Assertions: 2, Failures: 1.

  • 相关阅读:
    二分查找算法
    js 分享QQ、QQ空间、微信、微博
    linux安装redis
    redis linux开机启动 (简单高效)
    js 自定义阻止事件冒泡函数
    js常见删除绑定的事件
    js自定义方法绑定元素事件
    js 中 attachEvent 简示例
    idea无法正常显示jsp页面
    get请求的时候特殊符号的注意事项
  • 原文地址:https://www.cnblogs.com/uniqid/p/4150914.html
Copyright © 2011-2022 走看看