Java Reference
In-Depth Information
Created file StockWatcherTest-hosted.launch
Created file StockWatcherTest-web.launch
Created file StockWatcherTest-hosted.cmd
Created file StockWatcherTest-web.cmd
The .launch files are Eclipse launch configurations and the .cmd files are command-
line scripts. Use these files to invoke the generated test case in web or hosted mode.
You may need to adapt the scripts for your location of the JU nit and GWT .jar files.
13.8.4
Running test cases
Using Eclipse, running a test is easy. You
right-click a test case class and choose
Run As or Debug As and then choose
GWT JU nit Test to run the test in hosted
mode or GWT JU nit Test (Web Mode) to
run the test in web mode, as shown in
figure 13.6.
To use Ant, you need to make sure
your build file points to the GWT SDK . Using a GWT example build file as a template,
edit the gwt.sdk property to point to the GWT directory.
Figure 13.6
Running a test
13.8.5
Setup and teardown
A GWTTestCase subclass can override the JU nit methods setUp and tearDown with the
following restrictions:
You can't call GWT JavaScript Native Interface ( JSNI ) methods.
You can't call code that depends on deferred binding, which includes most of
the UI library.
GWT 1.5 remedies these issues by the addition of two methods available for overriding:
gwtSetUp runs before each test case method.
gwtTearDown runs after each test case method.
13.8.6
Creating a test suite
The benefit of using a test suite with GWT goes beyond grouping related tests
together. A performance gain is possible by using a GWT test suite. GWT sorts test cases
in a suite by module name as returned by getModuleName . This causes all tests with the
same module name to run one after the other.
To create a test suite, you can start with the Eclipse JU nit Test Suite Wizard. For
example, to create a test suite that includes all test cases in a package, go to the Pack-
ages view, right-click a package, and choose New and then Other. In the New dialog
box, open the JU nit node and choose JU nit Test Suite. Listing 13.16 shows the gener-
ated code with two changes we explain next.
 
 
 
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search