php一个简单的测试工具simpletest
时间:2011-03-30
来源:互联网
转:jackyrong
phpunit是很好的单元测试工具,而本文介绍一款更轻量级的单元测试工具,开源的,
simpletest,
1 下载:
http://sourceforge.net/projects/simpletest/,
可惜文档及项目主站要那个XXX,大家懂的
2 使用
下载后,只要测试文件中包含如下两个文件,就可以用了
复制代码
3 比如测试一个界面吧
复制代码
还可以测试表单的提交动作呢
复制代码
运行后会看到通过的情况
再举一个单元测试的例子:
比如有个类LOG,是在磁盘上建立文件
复制代码
测试方法中所有都默认以test开头的,这点要注意,最后用$test->run(new HtmlReporter());表示以HTML格式输出
php一个简单的测试工具simpletest
phpunit是很好的单元测试工具,而本文介绍一款更轻量级的单元测试工具,开源的,
simpletest,
1 下载:
http://sourceforge.net/projects/simpletest/,
可惜文档及项目主站要那个XXX,大家懂的
2 使用
下载后,只要测试文件中包含如下两个文件,就可以用了
- <?php
- require_once('simpletest/autorun.php');
- require_once('simpletest/web_tester.php');
-
- ?>
- <?php
- 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", "[email protected]");
- $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,是在磁盘上建立文件
- <?php
- 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());
- ?>
作者: so_brave 发布时间: 2011-03-30

作者: ws00377531 发布时间: 2011-03-30
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28