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 ...
随机推荐
- Selenium 进行web自动化测试
1.安装火狐版本时注意,如果无法正常安装,应该点击右键---以管理员身份运行 2.安装成功后,选择工具--选项--高级--更新,停止其自动化更新 3.maven里面加载应有的selenium的组件
- socket编程——一个简单的样例
从一个简单的使用TCP样例開始socket编程,其基本过程例如以下: server client ++ ...
- Java SE学习之printf 日期转换符
本文是学习网络上的文章时的总结,感谢大家无私的分享. System.out.printf()方法能够对日期做处理输出. 相应列表 转换符 类型 举例 c 完整的日期和时间 Mon Feb 09 18: ...
- GNOME3启动时出错:Oh no! Something has gone wrong.Logout!
今天用虚拟机安装debian7.1,在启动的时候遇到登录失败的问题,用GNOME Classic可以登录,特地记录如下: 原文出处:http://r3dux.org/2011/11/how-to-fi ...
- SOAP web service用AFNetWorking实现请求
问: This is my current call to (asmx) SOAP web service: NSString *soapMessage = [NSString stringWithF ...
- java08 Set
Set: 无序不可重复,重复则覆盖,判断是不是重复也是通过equals方法判断的.HashSet和TreeSet,HashSet底层是HashMap. public static void main( ...
- InnoTop
是一个系统活动报告,类似于Linux性能工具,它与Linux的top命令相仿,并参考mytop工具而设计. 它专门用后监控InnoDB性能和MySQL服务器.主要用于监控事务,死锁,外键,查询活动,复 ...
- MVC - 布局
布局类似于APSX视图的母版页 用的是Razor的语法 创建布局 布局页面默认放在Shared目录 有几个自动生成的cshtml文件 删除它们 然后创建一个视图 命名为MyLayOut 取消勾选使用母 ...
- Manually connecting to the Oracle Linux Yum Server
Manually connecting to the Oracle Linux Yum Server 1. Download and Install Oracle Linux Note: The ...
- Servlet & JSP - Decorating Requests and Responses
Servlet API 提供了四个包装类:ServletRequestWrapper.ServletResponseWrapper.HttpServletRequestWrapper.HttpServ ...