Emergent Web Technologies Spring 2009 Class 12
Introduction
Activity 1
This activity uses the testing framework that comes with a standard Ruby on Rails installation. The Ruby on Rails community (and the Ruby community in general) are very enthusiastic about testing.
1 First, open up the Instant Rails console and create an application for testing by running the following commands
rails testing_app cd testing_app ruby script/generate scaffold Location name:string address:string city:string state:string zip:string rake db:migrate
Before testing, you'll also need to set up the testing database by running the following commands
rake db:migrate rake db:test:load
2 The scaffold command automatically generated some tests for your application. We'll be looking at the unit tests for the location model.
First, make sure that the generated tests are working. This will verify that your scaffolded project has been set up correctly.
cd test ruby unit/location_test.rb
If everything worked correctly, you should see a message that looks like this
Started . Finished in 0.25 seconds. 1 tests, 1 assertions, 0 failures, 0 errors
3 Now, open the generated test so that you can edit to actually your location model. You can find the test at the following location
test/unit/location_test.rb
Modify the location test so it looks like this
require 'test_helper'
class LocationTest < ActiveSupport::TestCase test "address works" do address = "11 E Adams" location = Location.new location.address = address assert_equal location.address, address end end
This simple test will test to make sure that the location address property actually works. Normally, you wouldn't need to test something simple like this, but we'll just work with the simplest examples for now.
Activity 2
This activity uses the Screw.Unit JavaScript testing framework. This is a simple and easy to use framework and, despite the name, it actually works pretty well.
Activity 3
This activity uses the Watir framework to remotely control your browser.