Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing Rails

Avatar for chaffeqa chaffeqa
October 05, 2011

Testing Rails

Extending the Age old debate: "To Test or not to Test..." in Rails

Avatar for chaffeqa

chaffeqa

October 05, 2011
Tweet

Other Decks in Programming

Transcript

  1. The "Revenue" of Tests • Ensure API functions correctly •

    Verify client functionality • Document, Decouple, and Focus code • Ease Refactoring • Reveal Edge Cases
  2. Ensure API functions correctly Everything is an API • Model

    uses ActiveRecord API • Controller uses Model API • View uses Controller API + Helper API
  3. Document, Decouple, and Focus Code Well written tests can function

    as specifications for how code should function. API should be Decoupled and Concise. Isolating the object to ensure correct performance
  4. Ease Refactoring When it comes time to refactor code, testing

    is crucial to: • Ensure functionality is maintained • Speed up refactor process by removing manual testing of refactored code • Provide benchmarks of performance increase
  5. Reveal Edge Cases Because we all know we hate doing

    this by hand... • What if someone doesn't enter a last name? • What if nil is returned by this query?
  6. What to Test 6 defacto categories of tests for Rails.

    • Models • Controllers • Views • Layouts • Helpers • Integration
  7. Controllers Tests Controller flow. • Before filters • Assigning values

    to variables • Flash Messages • What gets rendered / returned / redirected
  8. Views Tests individual views and partials. • Defines what a

    user needs to see • Defines where it appears in the Html (inside what div, class, id, ect)
  9. Helpers Helpers are an API for views to use, and

    should be just as isolated as models.
  10. Integration The user's view of the application. This level is

    as close to a browser experience as technology allows. It allows for stories/workflows that test things like:
  11. Revenue vs Cost Should testing be needed for this project?

    • How big is this project? • How long do we have to create this project? • How many programmers will be working on this project? • Will this project need refactoring? • Will the specs change on this project?
  12. Delegation of Effort • What percent of effort should be

    committed to each layer of testing? • Include/exclude Integration testing?