views:

431

answers:

2

I'm trying to set up and use Mockito into a GWT project, and I'm having trouble using it on the client side (in javascript). I tried to add a module and include Mockito, but it seems not to work (lots of errors). I also tried to do a full checkout from svn and integrate GWT in it that way, the same errors. How should this be done? Thanks.

A: 

Without more specifics I can only say that mocking frameworks make heavy use of dynamic proxies and run-time code generation which will not be compiled by GWT.

Your best bet is using these mocks in plain JUnit tests.

Robert Munteanu
+2  A: 

GWT code tested with mocking framework (like Mockito) runs in JVM and no compiling to JavaScript, obviously. Thus, any JavaScript-related implementations should be mocked or stubbed using mock objects.

One architecture that receives wide adoption in GWT and that simplifies testing is MVP (variation of MVC). MVP places majority of meaningful functionality inside classes called presenters. Presenters do not rely upon GWT implementation classes but instead depend on GWT interfaces (mostly). Then Mockito is applied to mock/stub those interfaces to unit test presenter classes.

This blog is full of examples on both MVP in GWT and testing with mock objects (EasyMock).

grigory