rails testing

Download Rails Testing

If you can't read please download the document

Upload: mikeblake

Post on 24-May-2015

898 views

Category:

Documents


2 download

DESCRIPTION

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

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?

  • Weareprogrammers, 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 erasedand
  • # 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

  • assertboolean
  • assert_equalexpected, actual
  • assert_raise*args
  • assert_instance_ofklass, object
  • assert_nilobject
  • assert_validobject

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]:
  • is not true.
  • 2) Error:
  • test_truth(QualificationTest):
  • NameError: undefined local variable or method `duh' for #
  • "