Reputation: 56894
I'm new to the very concept of the Google Web Toolkit (GWT) and as far as I can tell its a Java API and toolset that allows you to code up your client-side code in Java, and at some point (as a part of the build or dynamically as HttpRequests come in) it generates client-side JS from your Java code (if I'm wrong on any of this please correct me!).
Assuming I'm more-or-less correct, I'm wondering how you unit test it!? Do you write JUnit tests for the Java code, or do you write JSUnit tests for the resultant/generated JavaScript? And if you use JSUnit, how do you know the names and inner-workings of the generated functions since GWT optimizes and minifies everything it outputs? Thanks in advance!
Upvotes: 1
Views: 646
Reputation: 1371
First of all, you are correct: GWT generates Javascript code from your client side Java code. However for the sake of speed we test everything we can while it's still in Java.
You write standard JUnit tests which you extend from JUnit's TestCase
or GWTTestCase
.
The main difference between the two is the following:
You use GWTTestCase
for every class that uses any kind of native javascript code (widgets and graphical elements are like this). The compiler will use a "headless" browser to test these as javascript code and because of that these tests are very slow compared to the standard JUnit TestCase
.
Thats why you use standard TestCase for everything else (it's much faster as this runs as bytecode) and that's why it's a good idea to use MVP pattern to separate your view (code can you test with GWTTestCase
) from the rest of your program (code you can test with TestCase
).
Here and here are two good article about how GWT unit testing works and what patterns should you use to make your job easier.
Upvotes: 1
Reputation: 64541
Have a look here: https://developers.google.com/web-toolkit/doc/latest/DevGuideTesting
Basically, you're using JUnit all the way down: pure Java when that's possible, GWTTestCase
otherwise (running in an emulated browser in Java –HTMLUnit– or a real browser, either in DevMode or compiled to JS –aka prod mode–), and finally integration/acceptance tests with Selenium/WebDriver.
Upvotes: 1