亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源單元測(cè)試工具 > HttpUnit
HttpUnit-測(cè)試用例
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/3/13 15:38:46 ] 推薦標(biāo)簽:

  (1)環(huán)境設(shè)置:導(dǎo)入HttpUnit

  (2)開始實(shí)踐,寫一個(gè)測(cè)試接口,起名為L(zhǎng)oginTestInf:

請(qǐng)/*
 * Created on 2004-12-17
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.apollo.test.util;

/**
 * @author SixSun
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 *測(cè)試用例編號(hào) : 0001
 *測(cè)試用例名稱 : HttpUnit 登陸驗(yàn)證測(cè)試用例
 *測(cè)試目標(biāo) : 驗(yàn)證用戶登陸是否成功
 *測(cè)試過(guò)程 :
 *1、輸入登陸地址的頁(yè)面地址,驗(yàn)證該頁(yè)面是否可被正常訪問(wèn)。
 *2、驗(yàn)證被訪問(wèn)的頁(yè)面是否是登陸頁(yè)面。
 *3、輸入非法用戶名、密碼,驗(yàn)證登陸失敗。
 *4、輸入合法用戶名、密碼,驗(yàn)證登陸成功。
 */    
public interface LoginTestInf {
    public void testValidPage() throws Exception;
    public void testIsLoginPage() throws Exception;
    public void testBadLogin() throws Exception;
    public void testGoodLogin() throws Exception;
}


  (3)實(shí)現(xiàn)一個(gè)Junit TestCase 同時(shí) implements LoginTestInf 接口:

/*
 * Created on 2004-12-17
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.apollo.test.util;

import java.net.URL;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
 
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.GetMethodWebRequest;

import org.apollo.test.util.LoginTestInf;

/**
 * @author sixsun
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class LoginTest extends TestCase implements LoginTestInf {

 private String username = "suibian";
 private String password = "suibian";
 
    private WebConversation browser;
    private WebRequest requestIndex;
    private WebRequest requestLogin;
    private WebResponse responseIndex;
    private WebResponse responseLogin;
    private String urlSystem = "系統(tǒng)首頁(yè)網(wǎng)址";
    private String urlLogin = "登陸界面網(wǎng)址";
 /*
  * @see TestCase#setUp()
  */
 protected void setUp() throws Exception {
        browser =  new WebConversation();
        requestIndex = new GetMethodWebRequest(urlSystem);
        responseIndex  = browser.getResponse(requestIndex);
        requestLogin = new GetMethodWebRequest(urlLogin);
        responseLogin  = browser.getResponse(requestLogin);     
 }
 
    //輸入登陸地址的頁(yè)面地址,驗(yàn)證該頁(yè)面是否可被正常訪問(wèn)
    public void testValidPage() throws Exception{
           assertNotNull("zsonline在網(wǎng)絡(luò)上不存在!",responseIndex);
    }
 
    //驗(yàn)證被訪問(wèn)的頁(yè)面是否是登陸頁(yè)面
    public void testIsLoginPage() throws Exception{
           URL currentUrl = responseLogin.getURL();
           String currentUrlStr = currentUrl.getProtocol() + "://" +currentUrl.getHost() + currentUrl.getPath();
           assertEquals("登陸頁(yè)面不是zsonline首頁(yè)!" ,currentUrlStr,urlLogin);
    }
 
    //輸入非法用戶名、密碼,驗(yàn)證登陸失敗
    public void testBadLogin() throws Exception{
          WebForm form = responseLogin.getForms()[0];
          form.setParameter("username","badname");
          form.setParameter("password","badpassword");
          requestLogin = form.getRequest();
          responseLogin =  browser.getResponse(requestLogin);
          assertTrue("用戶名不存在,請(qǐng)確認(rèn)用戶名輸入是否完全正確(區(qū)分大小寫)!",
                  responseLogin.getText().indexOf("用戶名不存在,請(qǐng)確認(rèn)用戶名輸入是否完全正確(區(qū)分大小寫)!") != -1);
    }
 
   //輸入合法用戶名、密碼,驗(yàn)證登陸成功
    public void testGoodLogin() throws Exception{
          WebForm form = responseLogin.getForms()[0];
          form.setParameter("username",username);
          form.setParameter("password",password);//此處需要填寫真實(shí)密碼
          requestLogin = form.getRequest();
          responseLogin =  browser.getResponse(requestLogin);
          assertTrue("轉(zhuǎn)到'zsonline'【suibian】用戶首頁(yè)失敗!",responseLogin.getText().indexOf("用戶測(cè)試用戶_zsonline,您好!") != -1);   
    }
 
    public static TestSuite suite(){
        return new TestSuite(LoginTest.class);
      }
      public static void main(String args[]){
        TestRunner.run(suite());
      }
}

軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 日本色片网站 | 国产资源在线视频 | 一卡二卡在线 | 国产第四页 | 精品久草 | 手机看片国产免费 | 五月天婷婷视频 | 欧美成人综合视频 | 最近最新免费中文字幕高清 | 特级黄色视频毛片 | 2020国产精品永久在线观看 | 国产精品久久久久久 | 99r在线视频| 欧美日韩无线码在线观看 | 中文字幕有码在线播放 | 国产高清精品在线 | 宠文肉细致高h一对一 | 91精品国产美女福到在线不卡 | 日韩精品视频在线观看免费 | 久久亚洲综合网 | 色丝瓜视频 | 天天透天天操 | 久久午夜剧场 | 国产精品免费看久久久麻豆 | 国产日韩视频在线 | 狠狠色丁香久久婷婷综合_中 | 日日日射射射 | 黄色国产一级片 | 国产91久久最新观看地址 | 成人精品一区二区三区 | 在线不卡免费视频 | 亚洲国产日韩欧美在线as乱码 | 国产精品久久久久久久久免费观看 | 国产成人综合网亚洲欧美在线 | 日本中文字幕在线观看视频 | 就草草在线观看视频 | 免费性网站 | 免费看黄视频网站 | 高h喷水荡肉爽文1v1 | 伊人网网站 | 嫩草影院永久在线一二三四 |