Javatpoint Logo
Javatpoint Logo

GWT Testing

JUnit provides time-tested framework for testing GWT application. It consists of many tools which can directly create the test cases according to user needs.

Now, on the basis of web-project STOCK EXCHANGE(created in previous chapter) we perform JUnit testing.

  1. Like all GWT JUnit test cases, the StockExchangeTest class extends the GWT Test Case class in the com.google.gwt.junit.client package. You can create additional test cases by extending this class.
  2. The StockExchangeTest class has an abstract method (getModuleName) that must return the name of the GWT module. For StockExchange, that is com.google.gwt.sample.stockexchange.StockExchange.
  3. The StockExchangeTest class is generated with one sample test case tautological test, testSimple. This testSimple method uses one of the many assert functions that it inherits from the JUnit Assert class.
  4. The assertTrue(boolean) function asserts that the boolean argument passed in evaluates to true. If not, the testSimple test will fail when run in JUnit.

StockExchangeTest.java


Running unit tests

You can run JUnit tests four ways:

  1. from the command line, using the scripts generated by junitCreator
  2. in Eclipse, using the Google Plugin for Eclipse
  3. in Eclipse, using the Eclipse launch configuration files generated by webAppCreator
  4. in manual test mode

We are using Eclipse and Google plug-in:

The Google Plugin for Eclipse makes it easy to run tests in Eclipse.

  • Run the JUnit test in development mode.
  • From Package Explorer, right click on the test case you want to run, select Run As > GWT Junit Test
  • The simpleTest executes without error.
GWT Testing 1
  • Run the JUnit test in production mode.
  • From Package Explorer, right click on the test case you want to run, select Run As > GWT Junit Test (production mode)
  • The simpleTest executes without error.

Writing unit test

  • Write a JUnit test to verify that the constructor of the StockPrice class is correctly setting the new object's instance fields.
  • To the StockExchangeTest class, add the testStockPriceCtor method as shown below.

Rerun StockExchangeTest in development mode.

Both tests should pass:

Next TopicGWT JSON





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA