标签:style blog color io ar div cti sp log
单元测试 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); } } ?>
标签:style blog color io ar div cti sp log
原文地址:http://www.cnblogs.com/thinksasa/p/3951886.html