• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 追求代碼質量: 對 Ajax 應用程序進行單元測試[3]

    發表于:2008-07-04來源:作者:點擊數: 標簽:代碼質量單元AjaxAJAX
    關鍵字: 測試 現在我實現了對所有與 UI 相關的組件的編程式訪問(假設所有需要進行訪問的類都在同一個包內)。以后我可能需要使用其中一種訪問進行驗證。我現在希望限制 使用訪問器,如我已經指出的,這是因為 GWT 并非設計用來進行交互測試。所以,我不是真
    關鍵字:測試 現在我實現了對所有與 UI 相關的組件的編程式訪問(假設所有需要進行訪問的類都在同一個包內)。以后我可能需要使用其中一種訪問進行驗證。我現在希望限制 使用訪問器,如我已經指出的,這是因為 GWT 并非設計用來進行交互測試。所以,我不是真的要試圖測試某個按鈕實例是否被單擊,而是要測試 GWT 模塊是否會對給定的單詞調用服務器端代碼,并且服務器端會返回一個有效定義。方法為將 onModuleLoad() 方法的定義獲取邏輯推入(不是故意用雙關語?。┮粋€可測試方法中,如清單 3 所示:
     
        清單 3. 重構的 onModuleLoad 方法委托給更易于測試的方法
                   
    public void onModuleLoad() {
      HorizontalPanel inputPanel = new HorizontalPanel();
      inputPanel.setStyleName("disco-input-panel");
      inputPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

      Label lbl = this.getLabel();
      inputPanel.add(lbl);

      TextBox txBox = this.getTextBox();
      inputPanel.add(txBox);

      Button btn = this.getButton();

      btn.addClickListener(new ClickListener() {
       public void onClick(Widget sender) {
         submitWord();
       }
      });

      inputPanel.add(btn);
      inputPanel.setCellVerticalAlignment(btn,
          HasVerticalAlignment.ALIGN_BOTTOM);

      if(RootPanel.get("input-container") != null) {
       RootPanel.get("input-container").add(inputPanel);
      }

      Label output = this.getOutputLabel();
      if(RootPanel.get("output-container") != null) {
       RootPanel.get("output-container").add(output);
      }
    }
     


        如清單 3 所示,我已經把 onModuleLoad() 的定義獲取邏輯委托給 submitWord 方法,如清單 4 定義:


        清單 4. 我的 Ajax 應用程序的實質!
                   
    protected void submitWord() {
      String word = this.getTextBox().getText().trim();
      this.getDefinition(word);
    }

    protected void getDefinition(String word) {
     WordServiceAsync instance = WordService.Util.getInstance();
     try {
       instance.getDefinition(word, new AsyncCallback() {

       public void onFailure(Throwable error) {
        Window.alert("Error oclearcase/" target="_blank" >ccurred:" + error.toString());
       }

       public void onSuccess(Object retValue) {
        getOutputLabel().setText(retValue.toString());
       }
      });
     }catch(Exception e) {
       e.printStackTrace();
     }
    }

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>