phpunit使用(项目中)
来源:互联网 发布:编写c语言程序步骤 编辑:程序博客网 时间:2024/05/18 02:24
1.命令行(cmd)安装pear
2.命令行(cmd)安装phpunit(phpunit2在06年已废弃)
3.开始编写测试(1.继承类,2.test_开头的方法)
use \Logger;//打印logger类
use jianghu\growing\GuajiAction;//1引入类
use jianghu\location\Location;//2引入类
use jianghu\playerAction\PlayerAction;//3引入类
require_once (dirname(__FILE__) . "/../growing/guaji.php");//1引入类路径
require_once (dirname(__FILE__) . "/../location/location.php");//2引入类路径
require_once (dirname(__FILE__) . "/../playerAction/playerAction.php");//2引入类路径
require_once (dirname(__FILE__) . '/../config.php');//引入类
require_once (dirname(__FILE__) . '/../common/utils.php');//引入类
define ('GoodAccess',true);//引入类
require_once (dirname(__FILE__) . '/../action/actionProcess.php');//引入类
Logger::configure(dirname(__FILE__) . '/../log4php.xml');//引入类
Predis\Autoloader::register();//引入类
class Test2 extends PHPUnit_Framework_TestCase//集成
{
const CONFIG_PATH = "./config.txt";//配置文件路径
function setUp() {
print "setup testing environment\n";
}
/**
* 挂机(事件)
*/
function guaji_1() {
$putong = 0;
$jiyu = 0;
$qiyu = 0;
$handler = new GuajiAction("521d6ed190ce8ef00800000a");
$configArr = $this->configInfo();
$sys_total = $configArr['sys_总数'];//循环总次数
for($i=0; $i<$sys_total; $i++){
//$this->assertTrue( guaji_action() == 3 );
$wenziArr = $handler->guaji_action();
$wenzi = $wenziArr['event'];//事件
if($wenzi == "putong"){
$putong += 1;
}else if($wenzi == "jiyu"){
$jiyu += 1;
}else if($wenzi == "qiyu"){
$qiyu += 1;
}
}
// $logger = \Logger::getLogger("jianghu");
// $logger->debug("普通#".$putong);
// $logger->debug("机遇#".$jiyu);
// $logger->debug("奇遇#".$qiyu);
$putong1 = $sys_total*0.50;
$jiyu1 = $sys_total*0.49;
$qiyu1 = $sys_total*0.01;
print "putong= $putong/$putong1 际遇 $jiyu/$jiyu1 奇遇 $qiyu/$qiyu1\n";
$expected = 0.05;
$actual = abs(($putong/(float)$putong1)-1.0);
$this->assertLessThan($expected, $actual, "普通概率错误-puchong!$putong vs $putong1");
$actual = abs(($jiyu/(float)$jiyu1)-1.0);
$this->assertLessThan($expected, $actual, "际遇概率错误-jiyu!$jiyu vs $jiyu1");
$expected = 0.10; // 概率太低,增加容错
$actual = abs(($qiyu/(float)$qiyu1)-1.0);
$this->assertLessThan($expected, $actual, "奇遇概率错误-qiyu!$qiyu vs $qiyu1");
}
/**
* 接镖(押镖)
*/
function yabiao_2() {
$level1 = 0;
$level2 = 0;
$level3 = 0;
$level4 = 0;
$level5 = 0;
$handler = new Location();
$configArr = $this->configInfo();
$sys_total = $configArr['sys_总数'];//循环总次数
for($i=0; $i<$sys_total; $i++){
$result=$handler->testYaBiao();
$level = $result['level'];//等级
if($level == "一等镖"){
$level1 += 1;
}else if($level == "二等镖"){
$level2 += 1;
}else if($level == "三等镖"){
$level3 += 1;
}else if($level == "四等镖"){
$level4 += 1;
}else if($level == "五等镖"){
$level5 += 1;
}
}
$gailvLevel1 = $sys_total*0.05;
$gailvLevel2 = $sys_total*0.25;
$gailvLevel3 = $sys_total*0.40;
$gailvLevel4 = $sys_total*0.25;
$gailvLevel5 = $sys_total*0.05;
// $logger = \Logger::getLogger("jianghu");
// $logger->debug("一等镖#".$level1." / ".$gailvLevel1);
// $logger->debug("二等镖#".$level2." / ".$gailvLevel2);
// $logger->debug("三等镖#".$level3." / ".$gailvLevel3);
// $logger->debug("四等镖#".$level4." / ".$gailvLevel4);
// $logger->debug("五等镖#".$level5." / ".$gailvLevel5);
// $logger->debug("######");
print "Level1= $level1/$gailvLevel1 Level2 $level2/$gailvLevel2 Level3 $level3/$gailvLevel3 Level4 $level4/$gailvLevel4 Level5 $level5/$gailvLevel5\n";
$expected = 0.05;//一等镖
$actual = abs(($level1/(float)$gailvLevel1)-1.0);//1
$this->assertLessThan($expected, $actual, "level-1-biao# $level1 vs $gailvLevel1");
$actual = abs(($level2/(float)$gailvLevel2)-1.0);//2
$this->assertLessThan($expected, $actual, "level-1-biao# $level2 vs $gailvLevel2");
$actual = abs(($level3/(float)$gailvLevel3)-1.0);//3
$this->assertLessThan($expected, $actual, "level-1-biao# $level3 vs $gailvLevel3");
$actual = abs(($level4/(float)$gailvLevel4)-1.0);//4
$this->assertLessThan($expected, $actual, "level-1-biao# $level4 vs $gailvLevel4");
$actual = abs(($level5/(float)$gailvLevel5)-1.0);//5
$this->assertLessThan($expected, $actual, "level-1-biao# $level5 vs $gailvLevel5");
}
function configInfo() {
$logger = \Logger::getLogger("jianghu");
$path = Test2::CONFIG_PATH;
$fp=fopen($path,"r");//以只读的方式打开文件
while(!(feof($fp)))
{
$text=fgets($fp);//读取文件的一行
if($text){
$arrLine = explode(":",$text);
}
$key = $arrLine[0];//key
$value = $arrLine[1];//value
//组合数据
$configArr[$key] = $value;
}
fclose($fp);
return $configArr;
}
function test_myown() {
print "running a dummy test\n";
}
}
- phpunit使用(项目中)
- laravel 中 phpunit的使用
- Yii 1.1 中PHPUnit的使用
- PHP单元测试之PHP测试、PHPUnit的使用、在ThinkPHP中使用PHPUnit
- 在Eclipse中使用PHPUnit进行单元测试 | Using PHPUnit with eclipse
- PHPunit 中phpunit selenium 扩展的安装
- 【phpunit】phpunit初次安装使用简记
- PHPStorm中配置phpunit
- NetBeans 使用phpunit单元测试
- PHPUnit 基本使用
- 使用 PHPUnit 进行测试
- PHPUnit 安装和使用
- 使用Pear安装PHPUnit
- PHPUnit使用详解
- 开始使用PHPUnit
- PHPUnit的使用
- centos linux安装PHPUnit 配置PHPUnit (深入浅出PHPUnit 1)
- PHPUnit从零开始(2):编写 PHPUnit 测试
- 代码大全2_6——可以工作的类
- linux下使用静态库需要注意的几个问题
- 黑马程序员--面向对象之七:Collection集合框架
- C++中const型数据的小结
- 推荐python主要模块学习
- phpunit使用(项目中)
- XP搜索功能不能使用解决办法
- apache编译常见问题
- 我们来谈谈Unity3D 优化
- Linux 从源码编译安装 OpenSSL
- MD5加密算法
- Javase 基础语法注意笔记
- hudson自动发布jar到Nexus
- redhat添加服务