我将 GWT 2.4 与 JUnit 4.8.1 一起使用。在编写扩展 GWTTestCase 的类时,我想模拟单击页面上的按钮。目前,在我的 onModuleLoad 方法中,这个按钮只是一个本地字段......
public void onModuleLoad() {
final Button submitButton = Button.wrap(Document.get().getElementById(SUBMIT_BUTTON_ID));
...
// Add a handler to send the name to the server
GetHtmlHandler handler = new GetHtmlHandler();
submitButton.addClickHandler(handler);
如何从 GWTTestCase 模拟单击此按钮?我是否必须将此按钮公开为公共成员访问器是否有更优雅的方式来访问它?到目前为止,这是我的测试用例中的内容...
public class GetHtmlTest extends GWTTestCase {
// Entry point class of the GWT application being tested.
private Productplus_gwt productPlusModule;
@Override
public String getModuleName() {
return "com.myco.clearing.productplus.Productplus_gwt";
}
@Before
public void prepareTests() {
productPlusModule = new Productplus_gwt();
productPlusModule.onModuleLoad();
} // setUp
@Test
public void testSuccessEvent() {
// TODO: Simulate clicking on button
} // testSuccessEvent
}
谢谢, - 戴夫