【问题标题】:Fire event in gwt java testing not changing the value of checkboxgwt java测试中的火灾事件不改变复选框的值
【发布时间】:2016-11-23 07:14:36
【问题描述】:

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

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 的值保持为假,而 RadioButton2 保持为真。

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

【问题讨论】:

    标签: java unit-testing gwt radio-button


    【解决方案1】:

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

        radioButton.setValue(true,true) 
    

    【讨论】:

      猜你喜欢
      • 2013-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多