Better Software - November 2008 - (Page 27) R achel had successfully built her Web 2.0 Ajax application using Google Web Toolkit, and her boss and customers were ecstatic. Revenue had increased, which led to a steady stream of new business requirements. But there was a catch: Bugs appeared, got fixed, and mysteriously reappeared. Rachel found her team spending an increasing amount of time fixing bugs while new feature development slowed to a crawl. She remembered that test-driven development was a great way to build applications in a manner that prevented defects from reappearing. She knew that Google Web Toolkit had been built with testability in mind, so Rachel downloaded JUnit and started writing tests In the October 2008 issue of Better directly in JavaScript, as indicated by method called getModuleName, which Software magazine, part one of this se- the keyword “native” in the definition returns a string containing the name of ries introduced the Google Web Toolkit of getCellElement. As shown in listing your GWT code module as defined in (GWT), a tool for building cross-browser 1, many of the GWT libraries include your application’s module configuration Ajax applications written in Java. GWT some native code—in particular, all wid- XML file. (GWT applications can be compiles Java code into JavaScript and gets that manipulate the Domain Object grouped into reusable modules, each of provides a component library that is Model (DOM). Thus, when your unit which contains an XML file descriptor cross-browser compatible and memory- tests execute native JavaScript, you must with information including source code leak proof. This means that you can be running in an environment where it location, dependencies, target browsers, focus on writing your application busi- can be executed, such as the hosted- etc.) ness logic instead of handling the acci- mode browser provided by GWT. When you run your test, the GWT dental complexity of supporting multiple To test native JavaScript code, GWT framework starts up an invisible (or browsers. provides a subclass of JUnit’s TestCase “headless”), hosted-mode browser and Another core feature of public void setStylePrimaryName(int row, int column, String styleName) { GWT is testability, which UIObject.setStylePrimaryName(getCellElement(bodyElem, row, column), means it’s easy to unit test styleName); your application. This makes } it possible to write GWT applications test first—an agile private native Element getCellElement(Element table, int row, int col) /*-{ practice that helps build relivar out = table.rows[row].cells[col]; able and extensible applicareturn (out == null ? null : out); tions. This article introduces }-*/; GWT’s testing infrastructure and demonstrates how to Listing 1 build an Ajax application test first. public class MeetingSummaryLabelTest extends GWTTestCase { gwt’s testing infrastructure Since a GWT application is almost entirely written in Java, you can test almost all of it using standard JUnit tests. However, GWT also includes a special subclass of JUnit’s TestCase that can test code that requires JavaScript at run time. While all of your client-side Java code will ultimately be compiled to JavaScript, only some of it directly uses code implemented as JavaScript. For example, the code in listing 1 is from the GWT HTMLTable class. This code sample demonstrates a method written in Java (setStylePrimaryName) that relies on code implemented public String getModuleName() { return “com.danielwellman.booking.Booking”; } // Add tests here } Listing 2 called GWTTestCase. This base class allows you to implement your JUnit test case as you normally would. In fact, GWTTestCases look almost identical to the standard JUnit TestCase shown in listing 2. The only visible difference is that all GWTTestCases must override an abstract www.StickyMinds.com then evaluates your test case against it. What this means is that all the facilities of the hosted browser are available to your test case. You can run native JavaScript functions, render widgets, or invoke asynchronous remote procedure calls. Furthermore, you can run your tests either as a hybrid of Java and JavaScript NOVEMBER 2008 BETTER SOFTWARE 27 http://www.nxtbook.com/nxtbooks/sqe/bettersoftware1008/index.php?startid=36 http://www.nxtbook.com/nxtbooks/sqe/bettersoftware1008/index.php?startid=36 http://www.StickyMinds.com
Table of Contents Feed for the Digital Edition of Better Software - November 2008 Better Software - November 2008 Contents Mark Your Calendar Contributors eLightenment Technically Speaking Code Craft Test Connection Management Chronicles Getting Agile with User-Centered Design Google Web Toolkit Simple Summaries of Complex Projects Product Announcements 10 Things You Might Not Know About … The Last Word Ad Index Better Software - November 2008 Better Software - November 2008 - (Page Intro) Better Software - November 2008 - (Page bellyband1) Better Software - November 2008 - (Page bellyband2) Better Software - November 2008 - Better Software - November 2008 (Page Cover1) Better Software - November 2008 - Better Software - November 2008 (Page Cover2) Better Software - November 2008 - Better Software - November 2008 (Page 1) Better Software - November 2008 - Better Software - November 2008 (Page 2) Better Software - November 2008 - Contents (Page 3) Better Software - November 2008 - Mark Your Calendar (Page 4) Better Software - November 2008 - Mark Your Calendar (Page 5) Better Software - November 2008 - Contributors (Page 6) Better Software - November 2008 - Contributors (Page 7) Better Software - November 2008 - eLightenment (Page 8) Better Software - November 2008 - eLightenment (Page QA1) Better Software - November 2008 - eLightenment (Page QA2) Better Software - November 2008 - eLightenment (Page 9) Better Software - November 2008 - eLightenment (Page 10) Better Software - November 2008 - eLightenment (Page 11) Better Software - November 2008 - eLightenment (Page 12) Better Software - November 2008 - Technically Speaking (Page 13) Better Software - November 2008 - Code Craft (Page 14) Better Software - November 2008 - Code Craft (Page 15) Better Software - November 2008 - Code Craft (Page 16) Better Software - November 2008 - Code Craft (Page 17) Better Software - November 2008 - Test Connection (Page 18) Better Software - November 2008 - Test Connection (Page 19) Better Software - November 2008 - Management Chronicles (Page 20) Better Software - November 2008 - Management Chronicles (Page 21) Better Software - November 2008 - Getting Agile with User-Centered Design (Page 22) Better Software - November 2008 - Getting Agile with User-Centered Design (Page 23) Better Software - November 2008 - Getting Agile with User-Centered Design (Page 24) Better Software - November 2008 - Getting Agile with User-Centered Design (Page 25) Better Software - November 2008 - Google Web Toolkit (Page 26) Better Software - November 2008 - Google Web Toolkit (Page 27) Better Software - November 2008 - Google Web Toolkit (Page 28) Better Software - November 2008 - Google Web Toolkit (Page 29) Better Software - November 2008 - Google Web Toolkit (Page 30) Better Software - November 2008 - Google Web Toolkit (Page 31) Better Software - November 2008 - Google Web Toolkit (Page 32) Better Software - November 2008 - Google Web Toolkit (Page 33) Better Software - November 2008 - Simple Summaries of Complex Projects (Page 34) Better Software - November 2008 - Simple Summaries of Complex Projects (Page 35) Better Software - November 2008 - Simple Summaries of Complex Projects (Page 36) Better Software - November 2008 - Simple Summaries of Complex Projects (Page 37) Better Software - November 2008 - Simple Summaries of Complex Projects (Page 38) Better Software - November 2008 - Simple Summaries of Complex Projects (Page 39) Better Software - November 2008 - Simple Summaries of Complex Projects (Page 40) Better Software - November 2008 - Simple Summaries of Complex Projects (Page 41) Better Software - November 2008 - Product Announcements (Page 42) Better Software - November 2008 - Product Announcements (Page 43) Better Software - November 2008 - Product Announcements (Page 44) Better Software - November 2008 - Product Announcements (Page 45) Better Software - November 2008 - 10 Things You Might Not Know About … (Page 46) Better Software - November 2008 - The Last Word (Page 47) Better Software - November 2008 - Ad Index (Page 48) Better Software - November 2008 - Ad Index (Page Cover3) Better Software - November 2008 - Ad Index (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.