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.

  • 相关阅读:
    延迟加载时发生no session错误的解决办法
    零零散散的一些知识点(一)
    零零散散的一些知识点(二)
    自己写的一个日历表
    js复制网址
    load方法在延迟加载时可能出现的错误。
    JSON基本介绍
    JBOSS4.0 JDBC数据源配置大全
    EJB学习笔记一
    Android程序完全退出的方法
  • 原文地址:https://www.cnblogs.com/uniqid/p/4150914.html
Copyright © 2011-2022 走看看