Skip to content

Integration with Guice

Gael Lazzari edited this page Aug 27, 2012 · 7 revisions

Since a GWT application usually deals with a backend server, you may be interested in using Guice to manage your server side components, like RPC services.

gwt-test-utils comes with some classes to allow you to test your entire GWT + Guice stack very easily.

How to use

@GwtModule("com.googlecode.gwt.test.sample.GuiceSample")
public class GuiceSampleTest extends GwtGuiceTest {

  @Inject
  private MyService myService;  
  
  // your test methods go here...
}
  1. First, extend GwtGuiceTest, the base class for test with Guice.
  2. Like with GwtTest, you have to set the module under test with the @GwtModule annotation.
  3. That's it !

Your GwtGuiceTest subclasses can be injected with @Inject members, and hold a reference to the used Injector through the GwtGuiceTest.getInjector() protected method.
Also note that your RPC servlets will automatically be binded to their corresponding RemoteService interfaces !

If you want to write a CSV test scenario which should be integrated with Guice, just extend GwtGuiceCsvTest instead of GwtGuiceTest :-)

You can fork sample-guice and sample-guice-csv projects to see complete GWT + Guice applications and how to test them using gwt-test-utils.

Overriding default behaviour

TODO