Rails Testing
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Rails Testing

  • 1,409 views
Uploaded on

A look at Unit , Functional, and Integration testing using the Rails Framework.

A look at Unit , Functional, and Integration testing using the Rails Framework.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,409
On Slideshare
1,409
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Testing on Rails
  • 2. Testing on Rails
    • Unit Tests
      • Models
    • Functional Tests
      • Controllers
      • Views
    • Integration Tests
      • Application
    • Fixtures
      • Data to support the Tests
  • 3.
      • Every Application get's tested, eventually.
    Why Test?
  • 4. Why Automate Tests?
    • We are programmers, right?
    • Computer's are great at performing mundane repeatable tasks.
    • Automated Regression Testing.
    • Refactoring is easier.
  • 5. Additional Benefits
      • Writing Tests makes better Programmers.
      • Automated Tests make better Applications.
    • Tests are a great warm-up / practice area.
        • With Unit Tests, “...you actually stand a chance of producing a product with close to zero defects.” -The Pragmatic Programmer
    • All the beautiful people write unit tests.
  • 6. My Favorite Mistake
    • # Warning: The database defined as 'test' will be erased and
    • # re-generated from your development database when you run 'rake'.
    • # Do not set this db to the same as development or production.
    • test:
    • adapter: mysql
    • database: bathroom_attendant_test
    • username: root
    • password:
    • host: localhost
  • 7. Unit Testing Models
    • Test Calculations
    • Test Validations
    • Test Callbacks
  • 8. Methods Available
    • assert boolean
    • assert_equal expected, actual
    • assert_raise *args
    • assert_instance_of klass, object
    • assert_nil object
    • assert_valid object
  • 9. Error vs. Failure
    • config
    • 1) Error:
    • test_truth(AttendantTest):
    • Mysql::Error: #28000Access denied for user 'root'@'localhost' (using password: NO)
    • 1) Failure:
    • test_truth(AttendantTest) [./test/unit/attendant_test.rb:8]:
    • <false> is not true.
    • 2) Error:
    • test_truth(QualificationTest):
    • NameError: undefined local variable or method `duh' for #<QualificationTest:0x2755958>
    • /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/test_process.rb:432:in `method_missing'
    • ./test/unit/qualification_test.rb:8:in `test_truth'
    • 4 tests, 3 assertions, 1 failures, 1 errors
    • rake aborted!
    • Command failed with status (1): [/usr/local/bin/ruby -Ilib:test &quot;/usr/local...]
    • (See full trace by running task with --trace)
  • 10. Functional Testing Controllers
    • Testing the Flow of the application
  • 11. The 4 Hashes of The Apocolypse
    • assigns : any objects that are stored as instance variables in actions for use in views
    • cookies : any objects cookies that are set
    • flash : any objects living in the flash
    • session : any object living in session variables
  • 12. Additional Methods Available
    • get
    • post
    • put
    • delete
    • head
    • assert_response
    • assert_template
    • assert_redirected_to
  • 13. Functional Testing Views
      • assert_select ( selector , *values, equality?, message?) { |elems| ... }
      • assert_select_rjs
      • assert_select_email
      • selector syntax is the same as
      • the syntax for CSS .
  • 14. Integration Testing
    • Testing Across Controllers
    • Testing User Stories
  • 15. Integration Methods
    • follow_redirect
    • xml_http_request
    • https
    • assert_difference
    • open_session
  • 16. Fixtures
    • YAML files
    • Dynamic Fixtures
    • Loading from Live Data
  • 17. Resources
      • Rails Manual
      • http://manuals.rubyonrails.com/read/chapter/28#page72
      • Integration Tests through 'script/console'
      • http://clarkware.com/cgi/blosxom/2006/04/04#HeadlessApp
      • Assertions Cheat Sheet
      • http://nubyonrails.topfunky.com/articles/2006/08/24/ruby-rails-test-rails-cheat-sheet
      • assert_select Cheat Sheet
      • http://blog.labnotes.org/2006/09/04/assert_select-cheat-sheet/
      • AWDR 2.0 Testing Chapter
      • http://media.pragprog.com/titles/rails2/Testing.pdf
      • SafetyNet Plugin
      • http://www.martinicity.net/articles/2007/02/07/safety-net
      • Difference between Mocks and Stubs
      • http://martinfowler.com/articles/mocksArentStubs.html