PHPUnit初试
先测试了一下加减,检查一下环境,又调用函数测试了服务器名。
源代码:
class DemoController extends \Think\Controller
{ /**
* @assert (5, 8) == 13
* @assert (16, 76) == 92
* @assert (6, 16) == 32
* @assert (6, 4) == 0
* @assert ('abc', 1) == 2
* @param int $a
* @param int $b
* @return int
*/
public function plus($a, $b)
{
return $a + $b;
} /**
* @assert (14, 8) == 6
* @assert (16, 6) == 10
* @assert (6, 4) == 0
* @assert ('45', 1) == 44
* @param int $a
* @param int $b
* @return int
*/
public function subtract($a, $b)
{
return $a - $b;
} public function connectToServer($serverName = null)
{
if ($serverName == null) {
throw new Exception("这不是一个服务器名");
}
$fp = fsockopen($serverName, );
return ($fp) ? true : false;
} }
生成测试文件:
class DemoControllerTest extends \PHPUnit_Framework_TestCase
{ /**
* @var DemoController
*/
protected $object; /**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = new DemoController;
} /**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{ } /**
* Generated from @assert (5, 8) == 13.
*
* @covers Home\Controller\DemoController::plus
*/
public function testPlus()
{
$this->assertEquals(
, $this->object->plus(, )
);
} /**
* Generated from @assert (16, 76) == 92.
*
* @covers Home\Controller\DemoController::plus
*/
public function testPlus2()
{
$this->assertEquals(
, $this->object->plus(, )
);
} /**
* Generated from @assert (6, 16) == 32.
*
* @covers Home\Controller\DemoController::plus
*/
public function testPlus3()
{
$this->assertEquals(
, $this->object->plus(, )
);
} /**
* Generated from @assert (6, 4) == 0.
*
* @covers Home\Controller\DemoController::plus
*/
public function testPlus4()
{
$this->assertEquals(
, $this->object->plus(, )
);
} /**
* Generated from @assert ('abc', 1) == 0.
*
* @covers Home\Controller\DemoController::plus
*/
public function testPlus5()
{
$this->assertEquals(
, $this->object->plus('abc', )
);
} /**
* Generated from @assert (14, 8) == 6.
*
* @covers Home\Controller\DemoController::subtract
*/
public function testSubtract()
{
$this->assertEquals(
, $this->object->subtract(, )
);
} /**
* Generated from @assert (16, 6) == 10.
*
* @covers Home\Controller\DemoController::subtract
*/
public function testSubtract2()
{
$this->assertEquals(
, $this->object->subtract(, )
);
} /**
* Generated from @assert (6, 4) == 0.
*
* @covers Home\Controller\DemoController::subtract
*/
public function testSubtract3()
{
$this->assertEquals(
, $this->object->subtract(, )
);
} /**
* Generated from @assert ('abc', 1) == 0.
*
* @covers Home\Controller\DemoController::subtract
*/
public function testSubtract4()
{
$this->assertEquals(
, $this->object->subtract('', )
);
} /**
* @covers Home\Controller\DemoController::connectToServer
* @todo Implement testConnectToServer().
*/
public function testConnectToServer()
{
// // Remove the following lines when you implement this test.
// $this->markTestIncomplete(
// 'This test has not been implemented yet.'
// );
$serverName = 'wwwcom';
$this->assertTrue($this->object->connectToServer($serverName) === false);
}
public function testConnectToServer2()
{
$serverName = 'www.baidu.com';
$this->assertTrue($this->object->connectToServer($serverName) !== false);
}
这里的服务器测试用例是手动加上去的!
执行结果:
..FFF..F..F / (%) Time: 44.42 seconds, Memory: .75Mb There were failures: ) Home\Controller\DemoControllerTest::testPlus3
Failed asserting that matches expected . D:\wamp\www\wxportal\tests\Application\Home\Controller\DemoController.classTest.php: ) Home\Controller\DemoControllerTest::testPlus4
Failed asserting that matches expected . D:\wamp\www\wxportal\tests\Application\Home\Controller\DemoController.classTest.php: ) Home\Controller\DemoControllerTest::testPlus5
Failed asserting that matches expected . D:\wamp\www\wxportal\tests\Application\Home\Controller\DemoController.classTest.php: ) Home\Controller\DemoControllerTest::testSubtract3
Failed asserting that matches expected . D:\wamp\www\wxportal\tests\Application\Home\Controller\DemoController.classTest.php: ) Home\Controller\DemoControllerTest::testConnectToServer2
Failed asserting that false is true. D:\wamp\www\wxportal\tests\Application\Home\Controller\DemoController.classTest.php: FAILURES!
Tests: , Assertions: , Failures: .
完成。
PHPUnit初试的更多相关文章
- 初试PHP单元测试TDD之安装PHPUnit
东风吹战鼓擂,一年一度的校招季开始了,最为一名即将踏入社会的搬砖工,自然也闲不下来了.各种总结.恶补.面经在所难免.当遇见敏捷开发时,有点蒙了,这是什么东东,绝对不能吃!既然是一种软件开发的方式,听上 ...
- PHPUnit整合ThinkPHP的库TPUnit
项目地址:https://github.com/web3d/TPUnit ThinkPHP PHPUnit框架集成,基于TP3.2,建议PHP 5.4以上环境. 单元测试应该是提高PHP编码质量的解决 ...
- 项目中初试PHP单元测试
只能叫初试,前面虽然做了一些PHPUnit与团队所用框架的整合,但在整个团队还没有人可以主动推动这个事情,而作为Leader最重要的一种能力应该是"让正确的事情发生",所以今天开始 ...
- 安装并使用PHPunit
安装并使用PHPunit Linux 下安装PHPunit PHP 档案包 (PHAR) 要获取 PHPUnit,最简单的方法是下载 PHPUnit 的 PHP 档案包 (PHAR),它将 PHPU ...
- PHPUnit笔记
PHPUnit是一个面向PHP程序员的测试框架,这是一个xUnit的体系结构的单元测试框架. 复杂的项目,通过单元测试能够快速排查bug,有效减少bug的产生.简单的项目,使用php自带的var_du ...
- phpunit 测试框架安装
PHPUnit是一个轻量级的PHP测试框架.它是在PHP5下面对JUnit3系列版本的完整移植,是xUnit测试框架家族的一员(它们都基于模式先锋Kent Beck的设计).来自百度百科 一.下载wg ...
- 安装最新版本的PHPUnit后,不能使用
我使用的是widows系统.本来3.7.8版本的Phpunit用的是非常顺畅的,最近重新安装phpunit,安装了最小版本,然后在使用的时候就会报很多各种错误.无奈之下只能降版本到3.7.8 首先要卸 ...
- 基于Netbeans的PHPUnit单元测试环境搭建
一.配置 PHPUnit截至2015-10-16,稳定版已更新至5.0.6,要求使用PHP v5.6及以上的环境才能使用. PHPUnit的4.8系列要求在PHP v5.3.3以上环境使用. Netb ...
- PHP PHPUnit的简单使用
1.window安装pear的教程:http://jingyan.baidu.com/article/ca41422fd8cf3d1eae99ed3e.html 2.在工作目录下,放两个文件: 1)C ...
随机推荐
- 怎么从代码中拿到栈回溯信息(call stack trace)
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:怎么从代码中拿到栈回溯信息(call stack trace).
- Java-日历表
效果图 import java.util.*; import java.text.*; class demo { public static void main(String[] args) { // ...
- CAS分析——Core
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- 高亮选中MEMO某一行
选中第5行 //转到指定行并选中这行的文本 procedure SelectLine(Memo1: TMemo; ln: Integer); begin Memo1.SelStart := SendM ...
- 让ie9之前的版本支持canvas
原来google的研发人员早就帮我们解决了这问题. 在这里我们得首先感谢google 在这链接http://excanvas.sourceforge.net/ 下载下来后 吧excanvas.js引入 ...
- 【点滴积累】通过特性(Attribute)为枚举添加更多的信息
转:http://www.cnblogs.com/IPrograming/archive/2013/05/26/Enum_DescriptionAttribute.html [点滴积累]通过特性(At ...
- mysqltuner
http://mysqltuner.com/ MySQLTuner-perl MySQLTuner is a script written in Perl that will assist you w ...
- 【转】C/C++中的日期和时间 TIME_T与STRUCT TM转换——2013-08-25 16
http://www.cnblogs.com/Wiseman/archive/2005/10/24/260576.html 摘要: 本文从介绍基础概念入手,探讨了在C/C++中对日期和时间操作所用到的 ...
- 路径MTU
数据在以太网中的传输有长度有一个限制,其最大值一般情况下是1500字节.链路层的这个特性叫作MTU,也就是最大传输单元.不同类型的网络会有所不同的.如果IP层有一个数据报要传输,而且数据的长度比链路层 ...
- C#多线程编程(1):线程的启动
转:http://blog.csdn.net/zhoufoxcn/article/details/4402999 在实例化Thread的实例,需要提供一个委托,在实例化这个委托时所用到的参数是线程将来 ...