com.google.gwt.junit.client
Class GWTTestCase

java.lang.Object
  extended by TestCase
      extended by com.google.gwt.junit.client.GWTTestCase
Direct Known Subclasses:
Benchmark

public abstract class GWTTestCase
extends TestCase

Acts as a bridge between the JUnit environment and the GWT environment. We hook the run method and stash the TestResult object for later communication between the test runner and the unit test shell that drives the test case inside a hosted browser.

There are two versions of this class. This version is the binary version that derives from JUnit's TestCase and handles all the work of starting up the GWT environment. The other version is a translatable class that is used within the browser. See the translatable subpackage for the translatable implementation.


Nested Class Summary
static class GWTTestCase.BaseStrategy
          The base class for strategies to use for tests.
static class GWTTestCase.TestModuleInfo
          Information about a synthetic module used for testing.
 
Field Summary
static java.util.Map<java.lang.String,GWTTestCase.TestModuleInfo> ALL_GWT_TESTS
          Records all live GWTTestCases by synthetic module name so we can optimize run they are compiled and run.
 
Constructor Summary
GWTTestCase()
          A new instance of your subclass is constructed for each test method that is to be run.
 
Method Summary
 void addCheckpoint(java.lang.String msg)
          Deprecated. This method will be removed when web mode supports stack traces. It can be useful for debugging web mode failures, but production code should not depend on it.
 boolean catchExceptions()
          Determines whether or not exceptions will be caught by the test fixture.
 void clearCheckpoints()
          Deprecated. This method will be removed if and when web mode supports stack traces. It can be useful for debugging web mode failures, but production code should not depend on it
static java.lang.String[] getAllTestModuleNames()
          Get the names of all test modules.
 java.lang.String[] getCheckpoints()
          Deprecated. This method will be removed if and when web mode supports stack traces. It can be useful for debugging web mode failures, but production code should not depend on it
static int getModuleCount()
          Get the number of modules.
abstract  java.lang.String getModuleName()
          Specifies a module to use when running this test case.
 JUnitShell.Strategy getStrategy()
          Get the GWTTestCase.BaseStrategy to use when compiling and running this test.
 java.lang.String getSyntheticModuleName()
          Get the synthetic module name, which includes the synthetic extension defined by the GWTTestCase.BaseStrategy.
static GWTTestCase.TestModuleInfo getTestsForModule(java.lang.String syntheticModuleName)
          Get the set of all JUnitHost.TestInfo for the specified module.
 boolean isPureJava()
          Returns whether this test case should be run in pure Java mode (non-GWT).
 void run(TestResult result)
          Stashes result so that it can be accessed during runTest().
 void setForcePureJava(boolean forcePureJava)
          Specifies whether this test case should be always run in pure Java mode (non-GWT).
 void setName(java.lang.String name)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALL_GWT_TESTS

public static final java.util.Map<java.lang.String,GWTTestCase.TestModuleInfo> ALL_GWT_TESTS
Records all live GWTTestCases by synthetic module name so we can optimize run they are compiled and run. Ordered so that we can precompile the modules in the order that they will run.

Constructor Detail

GWTTestCase

public GWTTestCase()
A new instance of your subclass is constructed for each test method that is to be run. You should avoid running code in your subclass constructor, initializer blocks, and field initializations, because if those code blocks must be runnable outside of the GWT environment. As an example of what could go wrong if you run code there, trying to run a JSNI method could generate an UnsatisfiedLinkError, and trying to call GWT.create(Class) could throw an UnsupportedOperationException. Instead, override gwtSetUp() and perform any initialization code there.

Method Detail

getAllTestModuleNames

public static java.lang.String[] getAllTestModuleNames()
Get the names of all test modules.

Returns:
all test module names

getModuleCount

public static int getModuleCount()
Get the number of modules.

Returns:
the module count.

getTestsForModule

public static GWTTestCase.TestModuleInfo getTestsForModule(java.lang.String syntheticModuleName)
Get the set of all JUnitHost.TestInfo for the specified module.

Parameters:
syntheticModuleName - the synthetic module name
Returns:
all tests for the module

addCheckpoint

@Deprecated
public final void addCheckpoint(java.lang.String msg)
Deprecated. This method will be removed when web mode supports stack traces. It can be useful for debugging web mode failures, but production code should not depend on it.

Add a checkpoint message to the current test. If this test fails, all checkpoint messages will be appended to the getException description. This can be useful in web mode for determining how far test execution progressed before a failure occurs.

Parameters:
msg - the checkpoint message to add

catchExceptions

public boolean catchExceptions()
Determines whether or not exceptions will be caught by the test fixture. Override this method and return false to let exceptions escape to the browser. This will break the normal JUnit reporting functionality, but can be useful in web mode with a JavaScript debugger to pin down where exceptions are originating.

Returns:
true for normal JUnit behavior, or false to disable normal JUnit getException reporting

clearCheckpoints

@Deprecated
public final void clearCheckpoints()
Deprecated. This method will be removed if and when web mode supports stack traces. It can be useful for debugging web mode failures, but production code should not depend on it

Clears the accumulated list of checkpoint messages.

See Also:
addCheckpoint(String)

getCheckpoints

@Deprecated
public final java.lang.String[] getCheckpoints()
Deprecated. This method will be removed if and when web mode supports stack traces. It can be useful for debugging web mode failures, but production code should not depend on it

Returns the current set of checkpoint messages.

Returns:
a non-null array of checkpoint messages
See Also:
addCheckpoint(String)

getModuleName

public abstract java.lang.String getModuleName()
Specifies a module to use when running this test case. Subclasses must return the name of a module that will cause the source for that subclass to be included.

Returns:
the fully qualified name of a module, or null to run as a pure Java (non-GWT) test case (same effect as passing true to setForcePureJava(boolean))
See Also:
isPureJava()

getStrategy

public JUnitShell.Strategy getStrategy()
Get the GWTTestCase.BaseStrategy to use when compiling and running this test.

Returns:
the test GWTTestCase.BaseStrategy

getSyntheticModuleName

public final java.lang.String getSyntheticModuleName()
Get the synthetic module name, which includes the synthetic extension defined by the GWTTestCase.BaseStrategy.

Returns:
the synthetic module name, or null if this test case is run in pure Java mode (non-GWT)
See Also:
isPureJava()

isPureJava

public boolean isPureJava()
Returns whether this test case should be run in pure Java mode (non-GWT). Returns true if and only if getModuleName() returns null, or setForcePureJava(boolean) was last invoked with true.


run

public final void run(TestResult result)
Stashes result so that it can be accessed during runTest().


setForcePureJava

public void setForcePureJava(boolean forcePureJava)
Specifies whether this test case should be always run in pure Java mode (non-GWT). Passing true has the same effect as returning null in getModuleName(). The setting is false by default.

Parameters:
forcePureJava - true to always run this test case in pure Java mode (non-GWT); false to run this test case in GWT mode if getModuleName() does not return null
See Also:
isPureJava()

setName

public void setName(java.lang.String name)