PHP code example of zt / unit-test
1. Go to this page and download the library: Download zt/unit-test library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zt / unit-test example snippets
namespace \Test\Controller;
class IndexController extends UnitTest{
/**
* 调用方法:
* 1. http://localhost/PROJECT_NAME/index.php?m=Test 自动执行全部测试文件
* 2. http://localhost/PROJECT_NAME/index.php?m=Test&controller=XXX 自动执行参数crontroller指定的文件
*/
function index(){
$this->run(true); //测试方式1 : 通过自动遍历测试文件的方式执行测试
}
function index2(){
$this->setController( array(__CLASS__ ,'\OtherClassName') ); //测试方式2 :设置将要执行的测试类
$this->run(); //执行测试代码
}
function testExample1(){ //该方法将自动被测试
$this->assertTrue(true);
$this->assertFalse(false);
}
function testExample2(){ //该方法将自动被测试
$this->assertEmpty(null);
$this->assertNotEmpty(true);
}
}