leonelag
20 Sep 2011, 9:05 AM
Hi,
I'm using GWT's JUnit test cases to test my user interface. I have a GXT composite which contains two toggle buttons, and they are in the same toggle group. The toggle buttons are for selecting a person's gender, male or female.
So my unit test consists in instantiating the widget, accessing the widget and calling its method toggle().
This is my test:
PersonForm form = new PersonForm();
form.render(RootPanel.get().getElement());
form.getButtonFemale().toggle(true);
assertTrue(form.getButtonFemale.isPressed());
assertFalse(form.getButtonMale.isPressed());
And my test fails because in the end, both buttons are pressed.
I have looked inside the source code for GXT's ToggleButton, and a button will only untoggle the other buttons when it was rendered. This means that buttons are not rendered inside my JUnit test. Note that in line 2, I tried to render() my widget inside the RootPanel of the application, but that did not cause the internal widgets to be rendered.
How can I create new instances of components inside a GWT test case, and make sure they are rendered ?
I'm using GWT's JUnit test cases to test my user interface. I have a GXT composite which contains two toggle buttons, and they are in the same toggle group. The toggle buttons are for selecting a person's gender, male or female.
So my unit test consists in instantiating the widget, accessing the widget and calling its method toggle().
This is my test:
PersonForm form = new PersonForm();
form.render(RootPanel.get().getElement());
form.getButtonFemale().toggle(true);
assertTrue(form.getButtonFemale.isPressed());
assertFalse(form.getButtonMale.isPressed());
And my test fails because in the end, both buttons are pressed.
I have looked inside the source code for GXT's ToggleButton, and a button will only untoggle the other buttons when it was rendered. This means that buttons are not rendered inside my JUnit test. Note that in line 2, I tried to render() my widget inside the RootPanel of the application, but that did not cause the internal widgets to be rendered.
How can I create new instances of components inside a GWT test case, and make sure they are rendered ?