360 likes | 381 Views
Learn strategies, tactics, and tools for ensuring error-free web apps through continuous validation. Dive into testing methods for human and machine-readability, browser differences, scalability, and productivity optimization.
E N D
Continuous Validation:Pursuing Error-Free Apps • Dane Avilla • Avilla Software
Biography • 10+ years software development • 5+ years web development • 2+ years Ruby/Rails
Overview • Goals: Why test • Strategies: Which approach • Tactics: How to succeed • Config & Demo • Questions
Web App Output • For humans • For machines
Current state-of-art testing • Human output: much effort • Machine output: little (no) effort
Consequences • Browser differences • Scalability • Productivity loss • Customer frustration
Web App == Code Generator • Input (HTTP GET/POST) • Output • HTML • CSS • JS
Two questions • Is output valid? • Does browser display output correctly? • (Ask these questions in this order!)
Solution • Validate Output • onsgmls, csslint, JSLint/JavaScript Lint • Difficult: bad docs, no single tool • Validate browser behavior (esp. for Ajax) • Human testing (waste of time) • Browser automation
Strategies • Infrastructure-level • App-level • Client-level
App-Level • Rails ‘after’ filters • Integrate with validation tools • Run when RAILS_ENV == :test
Client-Level • Browser Plug-In: http://addons.mozilla.org • HTML Validator • Relaxed the HTML Validator • Web spider/robot • Web Application Testing in Ruby (WATiR) • http://wtr.rubyforge.org • http://watir-on-rails.rubyforge.org
Tactics @ RubyForge • RaiLint • Lint for Rails • App-Level • DWatir • Distributed WATiR • Client-Level • RaiLint and DWatir are written by Dane G. Avilla
RaiLint @ RubyForge.org • App-level: Rails filters • Depends on (free) external tools • onsgmls: http://openjade.sourceforge.net • csslint: http://jigsaw.w3.org/css-validator • JavaScript Lint: http://www.javascriptlint.com • Removes most configuration headaches • java, onsgmls, and jsl must be on $PATH
RaiLint: App-Level • Adds filters to ActiveController::Base • Delegates to onsgmls, csslint, and JavaScript Lint • Validates (X)HTML, CSS, and JS • Adds rake test tasks to check .html, .js, and .css under $RAILS_APP/public
DWatir & Mofo: Client-Level • DWATiR • “Distributed Web Application Testing in Ruby” • Based on Rinda & Watir/SafariWatir/FireWatir • Central registry • Multi-browser/platform testing • Mofo: Microformats at http://mofo.rubyforge.org
Config & Demo • Sudoku Solver • App-Level • Client-Level
RaiLint: App-Level • Install to vendor/plugins/railint • Adds rake tasks (rake --task | grep railint) • From $RAILS_APP, run rake railint:config:all • Examples in $RAILINT_DIR/test • Sample errors: in $RAILINT_DIR, run rake --task • Override default JavaScript Lint config (jsl.conf) with $RAILS_APP/config/jsl.conf
Automate it all • RaiLint + DWatir • require ‘railint_test’ in a TestCase • Starts WeBrick in test mode when TestSuite starts • Shuts down WeBrick when TestSuite ends
Microformats for Testing • Subclass Microformat • Markup HTML output • Use API for testing expected output • “Free” customer API • NIH, but good technique
Microformat Implementation • require 'microformat' • class MicroRestaurant < Microformat one :id, :name, :phonenumberend • <div class="microrestaurant"> <span class="id">3</span> <span class="name">Obelisk</span> <span class="phonenumber">202-555-1414</span></div> • r = MicroRestaurant.find(:all => {:text => html_str}) =><#MicroRestaurant @id=“3” @name=“Obelisk” …>