支持各级别的代码自动测试
使用:
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();
}
文章来源于领测软件测试网 https://www.ltesting.net/