Your SlideShare is downloading. ×
0
Testing on Rails
Testing on Rails <ul><li>Unit Tests </li></ul><ul><ul><li>Models </li></ul></ul><ul><li>Functional Tests </li></ul><ul><ul...
<ul><ul><li>Every Application get's tested, eventually. </li></ul></ul>Why Test?
Why Automate Tests? <ul><li>We  are  programmers, right? </li></ul><ul><li>Computer's are great at performing mundane repe...
Additional Benefits <ul><ul><li>Writing Tests makes better Programmers. </li></ul></ul><ul><ul><li>Automated Tests make be...
My Favorite Mistake <ul><li># Warning: The database defined as  'test' will be erased  and </li></ul><ul><li># re-generate...
Unit Testing Models <ul><li>Test Calculations </li></ul><ul><li>Test Validations </li></ul><ul><li>Test Callbacks </li></ul>
Methods Available <ul><li>assert  boolean  </li></ul><ul><li>assert_equal  expected, actual  </li></ul><ul><li>assert_rais...
Error vs. Failure <ul><li>config </li></ul><ul><li>1) Error: </li></ul><ul><li>test_truth(AttendantTest): </li></ul><ul><l...
Functional Testing Controllers <ul><li>Testing the Flow of the application </li></ul>
The 4 Hashes of The Apocolypse <ul><li>assigns  : any objects that are stored as instance variables in actions for use in ...
Additional Methods Available <ul><li>get </li></ul><ul><li>post </li></ul><ul><li>put </li></ul><ul><li>delete </li></ul><...
Functional Testing Views <ul><ul><li>assert_select ( selector , *values, equality?, message?)  { |elems| ... } </li></ul><...
Integration Testing <ul><li>Testing Across Controllers </li></ul><ul><li>Testing User Stories </li></ul>
Integration Methods <ul><li>follow_redirect </li></ul><ul><li>xml_http_request </li></ul><ul><li>https </li></ul><ul><li>a...
Fixtures <ul><li>YAML files </li></ul><ul><li>Dynamic Fixtures </li></ul><ul><li>Loading from Live Data </li></ul>
Resources <ul><ul><li>Rails Manual </li></ul></ul><ul><ul><li>http://manuals.rubyonrails.com/read/chapter/28#page72 </li><...
Upcoming SlideShare
Loading in...5
×

Rails Testing

905

Published on

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

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
905
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Rails Testing"

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

    Clipping is a handy way to collect important slides you want to go back to later.

×