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 ...
随机推荐
- [置顶] 程序员必知(三):一分钟知道URI编码(encodeURI)
因为浏览器会用一些特殊的字符作为特定的意义,所以在要传输的内容上如果有这些特殊的字符的话,就需要对其进行转义才能正确传输,如以下字符为发送时候的关键字,即特殊字符 ;/?:@&=+$,# 所以 ...
- sping获取bean方法 解决资源耗尽
// ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"applicationCon ...
- Identity-第三章 Authorize原理解析
本篇旨在解析Identity中角色限制的原理. 需要的工具:Visual Studio.Reflector 问题提出: 1.当我们需要限制某个Controller的名称只需要某个或者某几个角色访问,这 ...
- CopyU!SW新版发布!
CopyU!SW新版发布,版本号为:2.1.412.213 主要更新内容如下: 此版本(2.1.412.213)主要作了如下更新: 1.修复了CopyU!SW版本中的运行模式规则的设定错 ...
- 调用webservice,解析返回数据为xml格式的字符串,进行数据绑定
DataSet ds = new DataSet(); byte[] byteArray = System.Text.Encoding.Unicode.GetBytes("<?xml ...
- AMQP与QPID简介
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- HTML增加删除邮件(table)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- PHP中的超级全局变量
PHP内置了一些超级全局变量,我们可以在脚本的任何地方使用和可见,下面记录一下这些全局变量的作用: 1.$_SERVER $_SERVER超级全局变量包含由web服务器创建的信息,它提供了服务器和客户 ...
- 【Python】分布式任务队列Celery使用参考资料
Python-Celery Homepage | Celery: Distributed Task Queue User Guide - Celery 4.0.2 documentation Task ...
- 安卓数据存储(3):SQLite数据库存储
SQLite简介 Google为Andriod的较大的数据处理提供了SQLite,他在数据存储.管理.维护等各方面都相当出色,功能也非常的强大.SQLite具备下列特点: 1.轻量级:使用 SQLit ...