tags:

views:

205

answers:

2

Can I test my client side GWT code without GWTTestCase? I've heard somewhere (I think it was one of the Google IO 2009 conferences) that they were successfully testing their code with a fake DOM, in the JVM and not in Javascript with the DOM. That would be brilliant. The point of this would be to gain speed (order of magnitude). Does anybody have any idea about how to do this? My first question on stack overflow, hope I'm doing this right. Thanks. Eugen.

+2  A: 

You should check out the Google I/O session by Ray Ryan.

Basically, you can use the Model/View/Presenter pattern and abstract away all the DOM-accessing code to the 'View' portion. By doing this, you can create a mock view and test the model/presenter using standard junit tests, running via the jvm, without the need for a browser or a DOM

Chi
+1  A: 

Not quite what you're looking for, but you should use the Model-View-Presenter pattern. Any code that requires the DOM should go in your View classes, and should be as dumb as possible. Complex logic goes in your Presenter classes. You can then test your presenter classes without needing a GWTTestCase.

E.g, a view might have a method like:

void setResponseText(String text);

Your presenter test case can then look something like:

void testSayHi() {
    expect(mockView.setResponseText("hi there"));
    replayMocks();
    presenter.sayHi();
    verifyMocks();
}
eschercycle