« Regular vs Underground Party | Main | Are you scared yet? »
Saturday
Jan242009

Testing RPC in GWT

There is very little information about sticking with GWTTestCase (instead of TestCase) and using fake server-side service implementation.

Problem:

You do not want to make any database-calls when your client-side tests run (when client-side tests make RPC calls to the service impl). You already have to live with crappy test speeds due to GWT test framework starting up an invisible hosted-mode browser to be able to execute JavaScript (that many widgets natively use) and you am too lazy to refactor your code to follow the GWT using MVC model example (to be able to stop using GWTTestCase).

Solution:

Define a separate fake service implementation (TestServiceImpl) and a module for testing (TestModule.gwt.xml). Simply make a copy of the production module, and change the contents of the servlet path tag to point to your TestSeviceImpl. Then make sure your GWTTestCase specifies this module in its getModuleName().

Voila! Tests run, they return expected values (either baked into TestServiceImpl or if you get fancy, your TestServiceImpl can implement a nice in-memory data store).
You can now be confident that your asynchronous RPC mechanism works as intended and you can test the production ServiceImpl separately (using JUnit).

EmailEmail Article to Friend

Reader Comments (1)

Try the SyncProxy (support both sync & async mode) to test GWT RPC services in JRE

See the post at http://www.gdevelop.com/w/blog/2010/01/10/testing-gwt-rpc-services/ for details

January 11, 2010 | Unregistered Commentertechbiz24

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>