zoukankan      html  css  js  c++  java
  • PHPUnit单元测试

    单元测试 PHPUnit

    <?php
    /**
     * 定义一个用来被测试的类RemoteConnect
     * @author json
     *
     */
    class RemoteConnect{
        public function connectServer($serverName = null){
            if($serverName == null){
                throw new Exception("This is not a server name!");
            }
            
            $fp = fsockopen($serverName,80);
            return $fp?true:false;
        }
        
        public function returnSampleObject(){
            return $this;
        }
    }
    
    /**
     * 定义一个用来测试RemoteConnect的类,
     * 但是要继承PHPUnit_Framework_TestCase。
     * @author json
     * 类名以Test结尾
     * $this->assertTrue:是单元测试的方法,有很多这样的方法。
     * 模块安装和用法看PHPUnit官网。
     */
    class RemoteConnectTest extends PHPUnit_Framework_TestCase{
        public function setUp(){}
        public function tearDown(){}
        //test to ensure that from the object is valid.
        public function testConnectIsValid(){
            echo "jaja";
            try{
                $connObj = new RemoteConnect();
                $serverName = null;
                $this->assertTrue($connObj->connectServer($serverName) !== false);
            }catch (Exception $e){
                $e->getMessage();
            }
        }
        public function testAbc(){
            $this->assertTrue(3+2 == 5);
        }
        
    }
    ?>
  • 相关阅读:
    java基础1
    display:inline
    运用<ul><li>做导航栏
    ul和li 基本用法分析(这里主要想学习怎么用在导航栏中)
    转换(旋转)transform
    典型相关分析
    相关性模型-相关系数
    拟合算法
    插值算法
    评估类模型之优劣解距离法Topsis模型
  • 原文地址:https://www.cnblogs.com/thinksasa/p/3951886.html
Copyright © 2011-2022 走看看