php一个简略的测试工具simpletest
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php一个简略的测试工具simpletest,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1754字,纯文字阅读大概需要3分钟。
内容图文
![php一个简略的测试工具simpletest](/upload/InfoBanner/zyjiaocheng/219/038f37bec5514f989cb81cc4a2c56164.jpg)
phpunit是很好的单元测试工具,而本文介绍一款更轻量级的单元测试工具,开源的,
simpletest,
1 下载:
http://sourceforge.net/projects/simpletest/,
可惜文档及项目主站要那个XXX,大家懂的
2 使用
下载后,只要测试文件中包含如下两个文件,就可以用了
require_once('simpletest/autorun.php');
require_once('simpletest/web_tester.php');
?>
3 比如测试一个界面吧
require_once('simpletest/autorun.php');
require_once('simpletest/web_tester.php');
class SimpleFormTests extends WebTestCase {
function testDoesContactPageExist() {
$this->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,是在磁盘上建立文件
require_once('simpletest/unit_tester.php');
require_once('simpletest/reporter.php');
require_once('../classes/log.php');
class TestOfLogging extends UnitTestCase {
function testCreatingNewFile() {
@unlink('/temp/test.log');
$log = new Log('/temp/test.log');
$this->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格式输出
内容总结
以上是互联网集市为您收集整理的php一个简略的测试工具simpletest全部内容,希望文章能够帮你解决php一个简略的测试工具simpletest所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。