gwt java测试中的fire事件不会改变checkbox的值

时间:2016-07-20 07:15:35

标签: java unit-testing gwt radio-button

我在一个组中添加了三个单选按钮,当我从浏览器加载页面时它工作正常。

Java代码:

@UiHandler({
"RadioButton1",
"RadioButton2",
"RadioButton3"
})  
void radioButtonClickHandler(ClickEvent event){
  if(RadioButton1.getValue()){
    // do something
  } else if(RadioButton2.getValue()) {
    // do something
  } else if (RadioButton3.getValue()){
    // do something
  }
}

我正在尝试为此函数编写测试用例。

public void TestRadio1ClickEvent(){
    // all values set 
    // Value of Radiobutton2 set to true
    view.RadioButton1.fireEvent(new ClickEvent() {});

    assertTrue(view.RadioButton1.getValue());
    assertFalse(view.RadioButton2.getValue());
    assertFalse(view.RadioButton3.getValue());
}

点击事件时,单选按钮的值不会改变。 RadioButton1的值保持为false并且RadioButton2保持为真。

我可以在点击处理程序中手动设置值,但我不想这样做。点击按钮与点击事件有何不同?是否单击更改单选按钮值,然后调用单击处理程序?

1 个答案:

答案 0 :(得分:1)

尝试在单选按钮上使用以下方法。 setValue(java.lang.Boolean value,boolean fireEvents)

    radioButton.setValue(true,true)