The Artima Developer Community
Sponsored Link

Java Community News
Testing GWT Ajax Applications

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Testing GWT Ajax Applications Posted: Jul 25, 2007 2:35 PM
Reply to this message Reply
Summary
In his latest IBM developerWorks article, Andrew Glover demonstrates GWTTestCase, the Google Web Toolkit's test helper class, and shows how to test asynchronous Ajax applications with GWT.
Advertisement

Testing Ajax applications has been a difficult task: Not only are such applications an amalgamation of a variety of technologies, such as HTML, CSS, JavaScript, and server-side code, but Ajax's asynchronous messaging paradigm adds more complexity to testing.

In his recent IBM developerWorks article, Unit testing Ajax applications, Andrew Glover focuses on testing techniques for Ajax applications written with the Google Web Toolkit (GWT). GWT allows developers to write Ajax applications in Java, and a Java-to-JavaScript compiler then translates Java code to appropriate JavaScript.

One advantage of this approach is better testability: Because GWT applications are written in Java, Java testing tools can be used to for GWT application testing. Glover notes that,

The GWT development team created a helper class dubbed GWTTestCase that extends from JUnit's 3.8.1 TestCase. This base class adds functionality for testing GWT code as well as handling some of the plumbing to get a GWT component up and running... it's meant to facilitate testing asynchronous aspects that can be triggered by UI interactions...

User interaction testing isn't possible with the GWTTestCase test case environment. When designing and building GWT applications, you must think about testing the code without relying on user interactions. This sort of thinking requires a decoupling of interaction code from business logic...

Glover highlights a few coding conventions to enable testability of GWT applications:

GWTTestCase requires you to play by some rules if you want to benefit from its testing magic. Luckily, the rules are simple:

  • All implementing test classes must reside in the same package as the GWT module you're attempting to test.
  • When running tests, you must pass in at least one VM argument to help specify which GWT mode (hosted or Web) to run the test in.
  • You must implement the getModuleName() method, which returns a String representation of your XML module file.

According to Glover, the GWT testing classes aid in unit testing asynchronous Ajax code as well:

Because an Ajax application that communicates with a server-side entity is asynchronous by nature, the GWT offers an additional Timer class that facilitates delaying JUnit long enough for asynchronous behavior to complete before an associated assertion...

[You'll] have to force JUnit to delay running to completion when [you] call ... a method via my test case; otherwise, the test will fail due to no response. This is where GWT's Timer class comes in handy. Timer allows me to override [a method] and finish the test case's logic within Timer instead.

What do you think of Ajax application testing? How would you compare the state of Ajax testing tools to Java testing tools?

Topic: Refactoring Java Code with Scala and Eclipse Previous Topic   Next Topic Topic: JUnit 4.4 Comes with a Few Assumptions, Theories, and Some New Syntax

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use