Book Review: Scripted GUI Testing with Ruby, by Ian Dees, published by Pragmatic Programmers, 192 pages, Aug. 2008, ISBN: 978-1-9343561-8-0, US $34.95
All software should be rigorously tested, during the development process, and before it is released. Automated testing helps software developers, testing teams and quality control (QC) teams perform comprehensive and effective testing, and find bugs quickly. This new book from the Pragmatic Bookshelf (in the Facets of Ruby Series) documents and demonstrates how to use the Ruby scripting language to test user interfaces reliably and repeatedly. The book covers a wide scope of testing needs, including techniques for scripted testing of MS-Windows GUIs, Java platform GUIs (for Linux, Mac, Windows, and others), or for web applications.
This book is a practical, quick moving tutorial based on real life, and real-world GUI applications. Author Ian Dees says, “This is the book I wish I had four years ago. That’s when I faced the equally unpleasant task of fixing old, broken GUI tests and coaxing a rickety third-party toolkit into running new tests. I started looking for a how-to guide on GUI testing to help me down this road. Unfortunately, there were none.” So Ian wrote the book he was wishing for.
Mr. Dees points out in the introduction (p.4) that many developers and software professionals have been suspicious or skeptical about test driven development (TDD). However, as he points out, “the important idea in TDD wasn’t the tests; it was the fact that writing the tests forces developers to think through how their code will behave.” After TDD, some people shifted their thought process, and began to speak of “behavior driven development” (BDD). As it turns out, Ruby is a very powerful and expressive language for scripting tests, and RSpec is a special Ruby tool in the Ruby coders toolbox. “RSpec was the first Ruby implementation of the ideas behind BDD.”
Many examples and test scripts are sprinkled throughout the book.
Chapter 2 covers some simple examples with MS-Windows, and Java Swing (the original Sun Java GUI widgets) with JRuby and lays a nice foundation for the variety of tests that can be performed with Ruby.
Chapter 3 provides more in depth coverage of how to use RSpec, which is a Ruby gem (or library), that turns Ruby into a powerful (yet simple) test description language. RSpec notation uses words like “describe” – for describing the test, and “should” – a verb for describing how if the test passes or fails.
Chapter 4 provides details on how to simplify your testing, and Chapter 5 provides many examples for special cases like testing passwords, wrangling documents, cutting and pasting, or searching and replacing (all under Ruby script control) to exercise many different tests of your application.
Chapter 6 and 7 provide more details about testing many kinds of apps, testing your tests, testing keystrokes, menus, mouse-clicks, and how to introduce randomness into the testing scenario. Chapter 8 delves into using FIT (Ward Cunningham’s Framework for Integrated Testing). Fortunately, there is a Ruby gem for FIT testing also, and Mr. Dees demonstrates how easy it is to utilize simple HTML tables to visualize your testing.
Chapter 9 moves into testing web applications by impersonating a browser, parsing the HTML, or driving the actual browser to perform specific behaviors. There are several great pointers and examples on how to use Selenium, and Selenium with RSpec, and example scenarios with AJAX also (going way beyond the simple HTML page load tests). Another great Ruby browser/web-site testing tool called Watir (Web Application Testing in Ruby) is also described. This is a great chapter. The testing techniques in chapter 9 are worth the price of the book, so if you buy the book, and only read chapter 9, you will be receiving great value.
The book has several more chapters describing RSpec Story Runner, specialized testing on the MAC, and alternate GUI testing for the MS-Windows platform, with Win32::GuiTest. The book concludes with a bibliography, nice summary of resources, and helpful websites related to Ruby and software testing, and an index of contents in the book.
Bonus: Rails Podcasts has an MP3 you can download – an interview with author Ian Dees about Scripted GUI Testing with Ruby.