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.

  • 相关阅读:
    简单聚合查询
    简单搜索入门
    简单的document操作
    快速检测集群的健康状况
    Log4j和Slf4j的比较
    javascript中escape()、unescape()、encodeURI()、encodeURIComponent()、decodeURI()、decodeURIComponent()比较
    Spring-data-jpa详解,全方位介绍。
    JSON关联属性转换异常
    原生类型 和 参数化类型
    Spring Data JPA
  • 原文地址:https://www.cnblogs.com/uniqid/p/4150914.html
Copyright © 2011-2022 走看看