How to do JUnit testing for a composite widget created using UIBinder?

201 views
Skip to first unread message

BM

unread,
Aug 25, 2011, 3:18:42 PM8/25/11
to Google Web Toolkit
I have created a stand alone custom widget using GWT UIBinder with the
help of GWT Designer.

The two files which I have are :

MultipleListBoxCustomWidget.java
MultipleListBoxCustomWidget.ui.xml

I use this widget is my GWT application which I use activites and
places framework and all my views are created using UIBinders.

I use this widget in one of my view with UIBinder tag referencing the
package name of the directory as the name spaces.

Question:
How do I Unit testing my widget code as it is all self-contained. The
functionality of the widget is show two list boxes on the screen with
4 buttons on the center. Each of these buttons are ">", "<", ">>" and
"<<" . This means I can move items from the list to another list
depending on which buttons are clicked. I kept the code as self-
contained and reusable so that I can pass any two different ArrayList
to my widget as two separate methods calls inside the widget and those
methods basically populates respective Listbox items inside the
widget. I also gave getter methods to return the changed item
arrangement of the ListBox items as ArrayList object as part of two
separate method calls.

Since the widget code is self-contained, my click handlers are inside
this java file MultipleListBoxCustomWidget.java for example -

@UiHandler("leftToRightButton")
void onLeftToRightButtonClick(ClickEvent event) {.....}


So testing is getting difficult. There is no controller because I
can't have a self-contained widget with MVP activities and places
inside to be used in another web applications which is designed using
activities and places.

Any advise?






Eric Metcalf

unread,
Aug 26, 2011, 6:12:22 PM8/26/11
to Google Web Toolkit

Jānis Ābele

unread,
Aug 27, 2011, 9:23:05 AM8/27/11
to google-we...@googlegroups.com
You could learn some principles form:

To easily test view you have to get rid of GWT.create(UiBinder.class) in your view.
 
So testing is getting difficult. There is no controller because I
can't have a self-contained widget with MVP activities and places
inside to be used in another web applications which is designed using
activities and places.

I don't understand. Why Presenter View could not be self-contained?

Alex Dobjanschi

unread,
Aug 28, 2011, 6:22:09 AM8/28/11
to google-we...@googlegroups.com
IMO You should not do unit testing for views. All you could test is what, that they look ok? Or they respond to app events? Or rather generate an app event, based on user input? While those cases are indeed valid, testing them by hand is very very easy. You should however have a Presenter/Mediator for that specific view, which acts in-between that view and the rest of application. It makes more sense to test that that presenter/mediator, making sure it works within app's context (generating events, responding to events).

But again, this is just my opinion.
My 2 cents,
Alex.

BM

unread,
Aug 29, 2011, 4:46:12 PM8/29/11
to Google Web Toolkit
So you are saying I should have three files for a custom composite
widget using UIBinder?

.java file
.ui.xml file
Presenter file ?
Reply all
Reply to author
Forward
0 new messages