发新话题
打印

单元测试分享

本主题由 Hex 于 2008-8-15 14:25 移动

单元测试分享

我仅仅是做测试,随便写的
首先在libraries里写你自己的类
复制内容到剪贴板
PHP 代码:
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Image {
var $url = "";
    function My_image($url)
    {
     echo "<hr/>";
     echo "<font color = 'red'>The url is:$url"."</font>";
     echo "<hr/>";
    }
   
    function Re_image($name)
    {
     echo "The image name is $name";
    }
   
    function A_image()
    {
     return "AA";
    }
}
?>
然后在controller里任一function里进行测试
复制内容到剪贴板
PHP 代码:
function image_unit()
        {
         echo "test...";
         $this->load->library('unit_test');
      $this->load->library('Image');
      $test = $this->image->a_image();
      $expected_result = 'AA';
      $test_name = 'Image Unit';
   echo $this->unit->run($test, $expected_result, $test_name);
        }
有点注意:调用时的类名,函数名必须小写,搞了我半天,汗。
你还可以进行类型测试,
这是对结果进行测试。


Test NameImage Unit
Test DatatypeString
Expected DatatypeString
ResultPassed
File NameD:\webroot\x.cn\CodeIgniter_1.6.3\system\application\controllers\welcome.php
Line Number549


若有什么错误,请指正。谢谢
本帖最近评分记录
  • Hex 威望 +5 原创内容 2008-8-15 14:27

TOP

支持一把。
虽然我从不测试:victory:

TOP

很棒,我给你转移并把语法加亮了。
加分~
QQ: 49489680
MSN: zhaochang_tj AT hotmail DOT com

TOP

引用:
原帖由 kissmumu 于 2008-8-15 14:22 发表
支持一把。
虽然我从不测试:victory:
如果是中小项目,作用不是很明显。
但是面对中大型项目,是非常重要的。
谢谢HEX:lol

TOP

发新话题