More nuggets:
Advanced RESTful Rails by Ben Scofield (Viget Labs)
Pick out the nouns from your app to determine the resources
Decide what methods to expose to those resources
Ajax actions generally use middle man which is a join model
Fast, Sexy, and Svelte: Our Kind of Rails Testing Dan Manges (ThoughtWorks), Zak Tamsen (ThoughtWorks)
Unit Test
- one method or object being tested at a time
- Avoiding Unit Test Britleness:
- gem “unit_record”
- ActiveRecord::Base.disconnect! keeps tests from hitting db
- To avoid db you could use fixtures (Difficult because you need to go back and forth to the fixture file)
- Or you could construct the object
Functional Testing Speed
- Gonna be slower – involve more objects and hit the db
- DeepTest speeds up functional tests
- Read DeepTest gem ReadMe to set up distributed tests – SUPER FAST!
Integration Tests
- Sometimes useful for special purpose tests
- performance tests
- smoke tests
- tests simulating multiple users
Acceptance tests
- Better for low levels of granularity
- Selenium RC – way to control the browser
- Writing Acceptance Tests:
- Encapsulate Pages
- Data Access:
- Can use Factory again to create entries
- Parallelization – multiple Selenium RCs
Integration Testing with RSpec's Story Runner by David Chelimsky (Articulated Man, Inc)
- Process
- Feature Injection
- Focus on outputs
- Acceptance Criteria – if tests pass, customer accepts it
- Popping the “Why?” stack – ask “Why?” until value comes out
Integration Testing:
Selenium RC (lets you test JavaScript/AJAX & you can watch it!)
- Because it’s slow you should only use for AJAX and use Webrat otherwise
- Multiple Sessions
The Great Test Framework Dance-off by Josh Susser (Pivotal Labs)
- RSpec for the structural level
- Shoula for test cases
- Test/unit for assertions
- Refactor with shoulda