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

您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > HttpUnit
HttpUnit-測試用例
作者:網絡轉載 發布時間:[ 2013/3/13 15:38:46 ] 推薦標簽:

  (1)環境設置:導入HttpUnit

  (2)開始實踐,寫一個測試接口,起名為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;

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

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


  (3)實現一個Junit TestCase 同時 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 = "系統首頁網址";
    private String urlLogin = "登陸界面網址";
 /*
  * @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);     
 }
 
    //輸入登陸地址的頁面地址,驗證該頁面是否可被正常訪問
    public void testValidPage() throws Exception{
           assertNotNull("zsonline在網絡上不存在!",responseIndex);
    }
 
    //驗證被訪問的頁面是否是登陸頁面
    public void testIsLoginPage() throws Exception{
           URL currentUrl = responseLogin.getURL();
           String currentUrlStr = currentUrl.getProtocol() + "://" +currentUrl.getHost() + currentUrl.getPath();
           assertEquals("登陸頁面不是zsonline首頁!" ,currentUrlStr,urlLogin);
    }
 
    //輸入非法用戶名、密碼,驗證登陸失敗
    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("用戶名不存在,請確認用戶名輸入是否完全正確(區分大小寫)!",
                  responseLogin.getText().indexOf("用戶名不存在,請確認用戶名輸入是否完全正確(區分大小寫)!") != -1);
    }
 
   //輸入合法用戶名、密碼,驗證登陸成功
    public void testGoodLogin() throws Exception{
          WebForm form = responseLogin.getForms()[0];
          form.setParameter("username",username);
          form.setParameter("password",password);//此處需要填寫真實密碼
          requestLogin = form.getRequest();
          responseLogin =  browser.getResponse(requestLogin);
          assertTrue("轉到'zsonline'【suibian】用戶首頁失敗!",responseLogin.getText().indexOf("用戶測試用戶_zsonline,您好!") != -1);   
    }
 
    public static TestSuite suite(){
        return new TestSuite(LoginTest.class);
      }
      public static void main(String args[]){
        TestRunner.run(suite());
      }
}

軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 欧美日韩国产不卡在线观看 | 国产欧美国日产网站 | 日韩色在线观看 | 青青视频免费在线 | 欧美日韩在线一区二区三区 | 蕾丝视频永久在线入口香蕉 | 九九精品在线视频 | 91精品国产一区二区三区左线 | 久久青青成人亚洲精品 | 99视频全部看免费观 | 国产老师制服丝袜裤视频 | 黄色福利影院 | 三级黄网站| 555夜色666夜色精品站 | 欧美成人精品一区二区 | 72式性无遮挡免费视频观看 | 免费成人视屏 | 98精品国产高清在线xxxx | 欧美sss视频 | 国产成人深夜福利短视频99 | 可以免费观看的一级毛片 | 天天爽天天乐 | 亚洲一本视频 | 在线中文字日产区乱码 | 日韩福利片午夜在线观看资源 | 一本色道久久88 | 亚洲国产剧情在线精品视 | 日皮黄色 | 天天做日日爱 | 国产特黄1级毛片 | 激情小视频在线播放免费 | 欧美高清成人videosex | 18性夜影院午夜寂寞影院免费 | 日韩亚洲欧美视频 | 69国产成人综合久久精 | 看黄在线| 国产视频福利在线 | 欧美日本免费 | 日b在线| 伦理片免费看 | 国产不卡高清 |