先测试了一下加减,检查一下环境,又调用函数测试了服务器名。

源代码:

 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初试的更多相关文章

  1. 初试PHP单元测试TDD之安装PHPUnit

    东风吹战鼓擂,一年一度的校招季开始了,最为一名即将踏入社会的搬砖工,自然也闲不下来了.各种总结.恶补.面经在所难免.当遇见敏捷开发时,有点蒙了,这是什么东东,绝对不能吃!既然是一种软件开发的方式,听上 ...

  2. PHPUnit整合ThinkPHP的库TPUnit

    项目地址:https://github.com/web3d/TPUnit ThinkPHP PHPUnit框架集成,基于TP3.2,建议PHP 5.4以上环境. 单元测试应该是提高PHP编码质量的解决 ...

  3. 项目中初试PHP单元测试

    只能叫初试,前面虽然做了一些PHPUnit与团队所用框架的整合,但在整个团队还没有人可以主动推动这个事情,而作为Leader最重要的一种能力应该是"让正确的事情发生",所以今天开始 ...

  4. 安装并使用PHPunit

    安装并使用PHPunit Linux 下安装PHPunit PHP 档案包 (PHAR)  要获取 PHPUnit,最简单的方法是下载 PHPUnit 的 PHP 档案包 (PHAR),它将 PHPU ...

  5. PHPUnit笔记

    PHPUnit是一个面向PHP程序员的测试框架,这是一个xUnit的体系结构的单元测试框架. 复杂的项目,通过单元测试能够快速排查bug,有效减少bug的产生.简单的项目,使用php自带的var_du ...

  6. phpunit 测试框架安装

    PHPUnit是一个轻量级的PHP测试框架.它是在PHP5下面对JUnit3系列版本的完整移植,是xUnit测试框架家族的一员(它们都基于模式先锋Kent Beck的设计).来自百度百科 一.下载wg ...

  7. 安装最新版本的PHPUnit后,不能使用

    我使用的是widows系统.本来3.7.8版本的Phpunit用的是非常顺畅的,最近重新安装phpunit,安装了最小版本,然后在使用的时候就会报很多各种错误.无奈之下只能降版本到3.7.8 首先要卸 ...

  8. 基于Netbeans的PHPUnit单元测试环境搭建

    一.配置 PHPUnit截至2015-10-16,稳定版已更新至5.0.6,要求使用PHP v5.6及以上的环境才能使用. PHPUnit的4.8系列要求在PHP v5.3.3以上环境使用. Netb ...

  9. PHP PHPUnit的简单使用

    1.window安装pear的教程:http://jingyan.baidu.com/article/ca41422fd8cf3d1eae99ed3e.html 2.在工作目录下,放两个文件: 1)C ...

随机推荐

  1. Wbemtest查询

    运行wbemtest,打开后连接命名空间,默认为“root\cimv2”,可以连接到”IIS管理命名空间(此为Windows Server 2008 R2)“ 查看该命名空间下所有可用的类:单击“枚举 ...

  2. php连接oracle数据库(linux)(转)

    php连接访问Oracle是用过oci函数,以下是整理的文档 1.安装Apache和php包 yum install -y httpd php* 2.下载Oracle组件 oracle-instant ...

  3. 谈谈JSON数据格式

    JSON 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.        本文主要是对JS操作JSON的要领做下总结.           在JSON中,有两种结构:对 ...

  4. Android自定义View之ProgressBar出场记

    关于自定义View,我们前面已经有三篇文章在介绍了,如果筒子们还没阅读,建议先看一下,分别是android自定义View之钟表诞生记.android自定义View之仿通讯录侧边栏滑动,实现A-Z字母检 ...

  5. Android 自定义View修炼-【2014年最后的分享啦】Android实现自定义刮刮卡效果View

    一.简介: 今天是2014年最后一天啦,首先在这里,我祝福大家在新的2015年都一个个的新健康,新收入,新顺利,新如意!!! 上一偏,我介绍了用Xfermode实现自定义圆角和椭圆图片view的博文& ...

  6. Android应用程序所包含的四种组件和DDMS

    关注用户组件         Activity                               编辑文本 .玩游戏 后台进程               Service           ...

  7. ERROR 1114 (HY000): The table 'adv_date_tmp' is full(Mysql临时表应用)

    场景:需要对现在数据库的数据进行批量的进行is_del=1的操作,但是遇到一个问题,在执行sql的时候发现sql不能在查询特定表的时候再嵌套查询来做update的操作,经过讨论,后续我们想到用临时表的 ...

  8. Socket.io 0.7 – Sending messages to individual clients

    Note that this is just for Socket.io version 0.7, and possibly higher if they don’t change the API a ...

  9. 编译inotify报错

    错误如下: configure: error: no acceptable C compiler found in $PATH 这是因为没有找到编译器的原因造成的 解决方法: 安装gcc [root@ ...

  10. <转载>解决div里面img的缝隙问题

    转载自:http://blog.sina.com.cn/s/blog_9fd5b6df01013mld.html   练习切图时发现img和父级div之间总是有2px空隙(chrome),上网搜索解决 ...