使用sampletest进行web测试

来源:互联网 发布:java对象是什么意思 编辑:程序博客网 时间:2024/05/23 09:41

 Web不测试不同于一般的单元测试,它是基于HTTP协议的.这表现在HTTP协议的特点是没有链接状态的.同时又涉及到于浏览器的交互(包括表单,链接状态),所以比较麻烦.SimpleTest提供了一套比较完整的基于PHP的测试脚本

一: 表单测试

<?php
require_once 'simpletest/unit_tester.php'
;
require_once 'simpletest/web_tester.php'
;
require_once 'simpletest/reporter.php'
;
class PassportRegister extends
 WebTestCase {

     
// 论坛登录测试

    function testPhpChina() {
        
$this->get('http://www.phpchina.com/bbs/logging.php?action=login'
);
        
$this->setField('username', 'your_username'
);
        
$this->setField('password', '******'
);
        
//元素的type属性为submit的input元素的name

        $this->clickSubmitByName('loginsubmit');
        
        
// 登录结果页包含文本

        $this->assertText('your_username');
    }
}
if (!defined('RUN_ALL'
)) {
    
$test = new
 PassportRegister();
    
$test->run(new HtmlReporter('utf-8'
));
}
?>

待续......

原创粉丝点击