您好,欢迎访问一九零五行业门户网

php一个简略的测试工具simpletest

php一个简单的测试工具simpletest
phpunit是很好的单元测试工具,而本文介绍一款更轻量级的单元测试工具,开源的,
simpletest,
1 下载:
   http://sourceforge.net/projects/simpletest/,
可惜文档及项目主站要那个xxx,大家懂的
2 使用
   下载后,只要测试文件中包含如下两个文件,就可以用了
3 比如测试一个界面吧
  get('http://www.example.com/contact.php');
    $this->assertresponse(200);
  }
}
?>
  还可以测试表单的提交动作呢
function testisproperformsubmissionsuccessful() {
$this->get('http://www.example.com/contact.php');
  $this->assertresponse(200);
$this->setfield(name, jason);
  $this->setfield(email, wj@example.com);
  $this->setfield(message, i look forward to hearing from you!);
$this->clicksubmit(contact us!);
$this->assertresponse(200);
  $this->asserttext(we will be in touch within 24 hours.);
}
运行后会看到通过的情况
再举一个单元测试的例子:
比如有个类log,是在磁盘上建立文件
assertfalse(file_exists('/temp/test.log'));
        $log->message('should write this to a file');
        $this->asserttrue(file_exists('/temp/test.log'));
    }
}
$test = &new testoflogging();
$test->run(new htmlreporter());
?>
测试方法中所有都默认以test开头的,这点要注意,最后用$test->run(new htmlreporter());表示以html格式输出
其它类似信息

推荐信息