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);
        }
        
    }
    ?>
  • 相关阅读:
    文件操作
    python中的函数递归和迭代问题
    函数的闭包与装饰器
    函数的名称空间和作用域
    python学习之路(四) ---函数
    python __name__问题
    浅谈python中的引用和拷贝问题
    Python中的缩进问题
    粘包现象
    socket编程
  • 原文地址:https://www.cnblogs.com/thinksasa/p/3951886.html
Copyright © 2011-2022 走看看