2月 20
目的:
支持各级别的代码自动测试
使用:
phpunit AllTests #全部测试
phpunit V2007_AllTests #V2007项目测试
phpunit V2007_Example_AllTests #V2007项目中Example模块测试
实现:
Tests
----| AllTests (All Test With test class: AllTests)
----| V2007 (A Project folder)
--------| AllTests.php (Project Testsuit, With test class: V2007_AllTests)
--------| Example.php (Module API Testcase, With test class: V2007_ExampleTest)
--------| Example (A Module folder)
------------| AllTests.php (Model Testsuit, With test class: V2007_Example_AllTests)
------------| ArrayTest.php (Function Testcase, With test class V2007_Example_ArrayTest)

文件及类的命名方式规范:
1. TestCase 以"Test"结尾
2. TestSuit 以"Tests"结尾
3. 目录结构和类名根据逻辑测试结构而定,如需V2007项目的Example模块的Array类/函数测试用例,则文件置于V2007/Example/ArrayTest.php, 其类名为V2007_Examlpe_ArrayTest
4. 每次测试以TestSuit进行,不支持单独运行TestCase测试

代码示例:

/**
 * AllTests.php
 */

if (!defined('PHPUnit_MAIN_METHOD')) {
    define('PHPUnit_MAIN_METHOD', 'AllTests::main');
}

//List your projects HERE
require_once 'V2007/AllTests.php';

class V2007_AllTests
{
    public static function main()
    {
        PHPUnit_TextUI_TestRunner::run(self::suite());
    }

    public static function suite()
    {
        $suite = new PHPUnit_Framework_TestSuite('V2007 rollenc.com');

        //Add your project tests HERE
        $suite->addTest(V2007_AllTests::suite());

        return $suite;
    }
}
if (PHPUnit_MAIN_METHOD == 'AllTests::main') {
    AllTests::main();
}
 



/**
 * V2007/AllTests.php
 */


if (!defined('PHPUnit_MAIN_METHOD')) {
    define('PHPUnit_MAIN_METHOD', 'V2007_AllTests::main');
}

//List your modules HERE
require_once 'V2007/Example.php'; // For APIs
require_once 'V2007/Example/AllTests.php';

class V2007_AllTests
{
    public static function main()
    {
        PHPUnit_TextUI_TestRunner::run(self::suite());
    }

    public static function suite()
    {
        $suite = new PHPUnit_Framework_TestSuite('V2007 System - Rollenc.com');
        $suite->addTestSuite('V2007_ExampleTest');
        $suite->addTest(V2007_Example_AllTests::suite());
        return $suite;
    }

    public static function suite()
    {
        $suite = new PHPUnit_Framework_TestSuite('V2007 System - rollenc.com');
        //Add your Module tests HERE
        $suite->addTest(V2007_Example_AllTests::suite());
        return $suite;
    }

}
if (PHPUnit_MAIN_METHOD == 'V2007_AllTests::main') {
    V2007_AllTests::main();
}
 



/**
 * V2007/Example/AllTest.php
 */

if (!defined('PHPUnit_MAIN_METHOD')) {
        define('PHPUnit_MAIN_METHOD', 'V2007_Example_AllTests::main');
}
//List your Function HERE
require_once 'V2007/Example/ArrayTest.php';
require_once 'V2007/Example/StringTest.php';
require_once 'V2007/Example/FunctionTest.php';

class V2007_Example_AllTests {
        public static function main() {
                PHPUnit_TextUI_TestRunner :: run(self :: suite());
        }

        public static function suite() {
                $suite = new PHPUnit_Framework_TestSuite('V2007 System - V2007_Example');

                $suite->addTestSuite('V2007_Example_ArrayTest');
                $suite->addTestSuite('V2007_Example_StringTest');
                $suite->addTestSuite('V2007_Example_FunctionTest');
                return $suite;
        }
}

if (PHPUnit_MAIN_METHOD == 'V2007_Example_AllTests::main') {
    V2007_Example_AllTests::main();
}
 



/**
 * V2007/Example/ArrayTest.php
 */

class V2007_Example_ArrayTest extends PHPUnit_Framework_TestCase
{
        public function setUp() {
                $this->a = array(1,2,3,4,5,6,7,8,9);
        }
       
        public function testA() {
                array_push($this->a, 0);
                $this->assertEquals(count($this->a), 10);
                $this->assertEquals(1, 1);
        }
        public function testB() {
                $this->assertEquals(count($this->a), 9);
        }
       
        public function tearDown() {
                $this->a = array();
        }
}
 


参考:
ZendFramework

作者 rollenc

| 主要出源 (0)
对此文章进行打分:
当前分数: 3.67 of 5 。 3 次打分。 345 次点击
Bookmark PHPUnit测试框架应用类及代码结构  at del.icio.us Digg PHPUnit测试框架应用类及代码结构 Mixx PHPUnit测试框架应用类及代码结构 Bloglines PHPUnit测试框架应用类及代码结构 Technorati PHPUnit测试框架应用类及代码结构 Fark this: PHPUnit测试框架应用类及代码结构 Bookmark PHPUnit测试框架应用类及代码结构  at YahooMyWeb Bookmark PHPUnit测试框架应用类及代码结构  at Furl.net Bookmark PHPUnit测试框架应用类及代码结构  at reddit.com Bookmark PHPUnit测试框架应用类及代码结构  at blinklist.com Bookmark PHPUnit测试框架应用类及代码结构  at Spurl.net Bookmark PHPUnit测试框架应用类及代码结构  at NewsVine Bookmark PHPUnit测试框架应用类及代码结构  at Simpy.com Bookmark PHPUnit测试框架应用类及代码结构  at blogmarks Bookmark PHPUnit测试框架应用类及代码结构  with wists Bookmark PHPUnit测试框架应用类及代码结构  at Ma.gnolia.com wong it! Bookmark using any bookmark manager! Stumble It!

0 引用

  1. 没有引用

0 回复

回复显示方式(直线程 | 分线程)
  1. 没有回复

新增回复


You can use [geshi lang=lang_name [,ln={y|n}]][/lang] tags to embed source code snippets
电子邮件地址将不会被显示,而仅将被用于发送电子邮件通知