您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 >
JFCUnit介紹
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2012/12/27 14:16:42 ] 推薦標簽:

測試用例代碼:

import java.util.*;

import javax.swing.*;

import junit.extensions.jfcunit.*;
import junit.extensions.jfcunit.eventdata.*;
import junit.framework.*;
import org.apache.regexp.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author leiwei
 * @version 1.0
 */

public class LoginScreenTest
    extends JFCTestCase {

  private LoginScreen loginScreen = null;
  private TestHelper helper = null;

  public LoginScreenTest(String name) {
    super(name);
  }

  protected void setUp() throws Exception {
    super.setUp();
    helper = new JFCTestHelper();
    loginScreen = new LoginScreen("LoginScreenTest: " + getName());
    loginScreen.setVisible(true);
  }

  protected void tearDown() throws Exception {
    loginScreen = null;
    helper.cleanUp(this);
    super.tearDown();
  }


  public void testUI() {
    JDialog dialog;

    JButton exitButton = (JButton) helper.findNamedComponent("ExitButton",
        loginScreen, 0);
    assertNotNull("Could not find the Exit button", exitButton);

    JButton enterButton = (JButton) helper.findNamedComponent("EnterButton",
        loginScreen, 0);
    assertNotNull("Could not find the Enter button", enterButton);

    JTextField userNameField = (JTextField) helper.findNamedComponent(
        "LoginNameTextField", loginScreen, 0);
    assertNotNull("Could not find the userNameField", userNameField);

    assertEquals("Username field is empty", "", userNameField.getText());

    JTextField passwordField = (JTextField) helper.findNamedComponent(
        "PasswordTextField", loginScreen, 0);
    assertNotNull("Could not find the passwordField", passwordField);

    assertEquals("Password field is empty", "", passwordField.getText());

    try {
      helper.enterClickAndLeave(new MouseEventData(this, enterButton));
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }

    List showingDialogs = helper.getShowingDialogs(loginScreen);
    assertEquals("Number of dialogs showing is wrong", 2, showingDialogs.size());

    dialog = (JDialog) showingDialogs.get(1);
    assertEquals("Wrong dialog showing up", "Login Error", dialog.getTitle());

    helper.disposeWindow(dialog, this);
  }

 

 

  public static Test suite() {
    return new TestSuite(LoginScreenTest.class);
  }


  public void TestUI(){}

  public static void main(String args[]) {
    junit.textui.TestRunner.run(suite());

  }

}

小結(jié)
1、    JFCUnit的基本框架與原理與Junit一樣,其實從實現(xiàn)上是完全基于Junit,是Junit在GUI界面測試上的有效擴展。
2、    JFCUnit功能十分強大,擅長對象實例檢查,各種人機界面響應事件的模擬,便于功能性檢查。
3、    JFCUnit不善于界面布局,美觀方面的檢查,看來人工測試還是不可缺少的。
4、    JFCUnit中對對象進行測試的基礎(chǔ)是獲得測試對象實例,關(guān)鍵是find…Component系列API的應用,具體查找主要基于兩個方面,對象組件的“Name”屬性和在容器中的Index,而這兩種方式都不是很直觀,具體使用何種方式也很大程度上取決于開發(fā)人員的編碼,具體使用時有一定難度和局限性。
5、    JFCUnit還有很多深入用法,比如支持GUI測試的多線程方法,支持XML方式測試,以后有時間再與大家分享。
6、    由于相關(guān)資料比較缺乏,很多測試經(jīng)驗完全是個人摸索得來,希望以后有人做更深入的研究。

上一頁12下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd