SlideShare a Scribd company logo
Testing on Rails
Testing on Rails Unit Tests Models Functional Tests Controllers Views Integration Tests Application Fixtures Data to support the Tests
Every Application get's tested, eventually. Why Test?
Why Automate Tests? We  are  programmers, right? Computer's are great at performing mundane repeatable tasks. Automated Regression Testing. Refactoring is easier.
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.
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
Unit Testing Models Test Calculations Test Validations Test Callbacks
Methods Available assert  boolean  assert_equal  expected, actual  assert_raise  *args  assert_instance_of  klass, object  assert_nil  object  assert_valid  object
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)
Functional Testing Controllers Testing the Flow of the application
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
Additional Methods Available get post put delete head  assert_response assert_template assert_redirected_to
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 .
Integration Testing Testing Across Controllers Testing User Stories
Integration Methods follow_redirect xml_http_request https assert_difference open_session
Fixtures YAML files Dynamic Fixtures Loading from Live Data
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

More Related Content

ODP
Rtt preso
PPTX
RSpec and Rails
PPTX
Angular Unit Testing
PDF
Vladyslav Romanchenko "How to keep high code quality without e2e tests"
PDF
Client side unit tests - using jasmine & karma
PPTX
TestCafe Meetup Malmberg
PPTX
j meter
Rtt preso
RSpec and Rails
Angular Unit Testing
Vladyslav Romanchenko "How to keep high code quality without e2e tests"
Client side unit tests - using jasmine & karma
TestCafe Meetup Malmberg
j meter

What's hot (20)

PPT
VodQA_ParallelizingCukes_AmanKing
PPTX
Testing React Applications
PPTX
Angular Unit Test
PDF
mocha sinon chai Dc jquery 4-24
PDF
Angular Unit Testing NDC Minn 2018
PPT
Dhanasekaran 2008-2009 Quick Test Pro Presentation
PPT
First QTP Tutorial
PDF
vREST for a new user
PPTX
An easy way to automate complex UI
PPTX
API Testing - The power of libraries (chai, cheerio.js ,lodash and moment.js)
PDF
Unit Testing in WordPress
PDF
Angular Unit Testing from the Trenches
PDF
Patterns of a “good” test automation framework
PPT
Test Driven Development using QUnit
PDF
[FullStack NYC 2019] Effective Unit Tests for JavaScript
PDF
Unit-testing and E2E testing in JS
PPTX
Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...
PDF
Testing with Rspec 3
PPTX
Unit testing of java script and angularjs application using Karma Jasmine Fra...
PPTX
utPLSQL: Unit Testing for Oracle PL/SQL
VodQA_ParallelizingCukes_AmanKing
Testing React Applications
Angular Unit Test
mocha sinon chai Dc jquery 4-24
Angular Unit Testing NDC Minn 2018
Dhanasekaran 2008-2009 Quick Test Pro Presentation
First QTP Tutorial
vREST for a new user
An easy way to automate complex UI
API Testing - The power of libraries (chai, cheerio.js ,lodash and moment.js)
Unit Testing in WordPress
Angular Unit Testing from the Trenches
Patterns of a “good” test automation framework
Test Driven Development using QUnit
[FullStack NYC 2019] Effective Unit Tests for JavaScript
Unit-testing and E2E testing in JS
Pester & PSScriptAnalyser - Power Test your PowerShell with PowerShell - Futu...
Testing with Rspec 3
Unit testing of java script and angularjs application using Karma Jasmine Fra...
utPLSQL: Unit Testing for Oracle PL/SQL
Ad

Viewers also liked (7)

PDF
Digitalizzare immagini
ODP
Metaprogramming
PPT
Hensel Presentation1
PPTX
Jenu Kurubar Children's Toys & Games
PPTX
What Is Happening At Jenu Kuruba Archive
PPTX
Footworks of Seraikella Chhau
PPT
Acl
Digitalizzare immagini
Metaprogramming
Hensel Presentation1
Jenu Kurubar Children's Toys & Games
What Is Happening At Jenu Kuruba Archive
Footworks of Seraikella Chhau
Acl
Ad

Similar to Rails Testing (20)

KEY
Test Coverage in Rails
PDF
Testing Legacy Rails Apps
KEY
How To Test Everything
PPTX
TDD & BDD
PPT
Acceptance Testing With Selenium
PDF
Thomas Fuchs Presentation
PDF
Adventures In JavaScript Testing
PPTX
Web tech: lecture 5
PDF
Getting Answers to Your Testing Questions
PDF
Beyond Testing: Specs and Behavior Driven Development
KEY
Tdd for BT E2E test community
ODP
Query Management system-Iv review
DOCX
PDF
Rethinking Testing
PDF
An Introduction to Unit Test Using NUnit
PDF
Testing Django Applications
PDF
2011-02-03 LA RubyConf Rails3 TDD Workshop
PPTX
Test in action – week 1
PDF
PPTX
Qunit Java script Un
Test Coverage in Rails
Testing Legacy Rails Apps
How To Test Everything
TDD & BDD
Acceptance Testing With Selenium
Thomas Fuchs Presentation
Adventures In JavaScript Testing
Web tech: lecture 5
Getting Answers to Your Testing Questions
Beyond Testing: Specs and Behavior Driven Development
Tdd for BT E2E test community
Query Management system-Iv review
Rethinking Testing
An Introduction to Unit Test Using NUnit
Testing Django Applications
2011-02-03 LA RubyConf Rails3 TDD Workshop
Test in action – week 1
Qunit Java script Un

Rails Testing

  • 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