Tests

As testing is one of the main goals of an MVP architecture, gwt-mpv strives to make testing as easy as possible.

It does this by providing out-of-the-box fake (stub) view objects, for both common GWT widgets (e.g. StubTextBox), and your own UiBinder-based views.

This means you can write tests that:

As a short example, ClientPresenterTest from the gwt-hack sample project includes a test of what happens on key up:

  @Test
  public void keyUpChangesNameLeft() {
    dto.name = "foo";
    presenter.bind();
    assertThat(view.name().getText(), is("foo"));
    assertThat(view.nameLeft().getText(), is("47 left"));

    view.name().press('b');
    assertThat(view.nameLeft().getText(), is("46 left"));
  }

}

Note how the view.name().press('b') call results in:

This flow of events is typical for rich, event-driven UIs, and the above test shows how gwt-mpv enables testing all of an application’s presenter logic, model logic, and view binding end-to-end succinctly, even while using fake, in-memory widgets.

For more information, see either stubs for information about the stubs themselves, or the tutorial for how ClientPresenterTest fits into the bigger picture.