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

Testing Best Practices

Testing Best Practices

Talk about testing best practices @colognerb Ruby User Group


May 16, 2012

More Decks by elitau

Other Decks in Programming


  1. PRODUCT QUALITY MEASUREMENT REFERENCE MODEL external quality quality in use

    internal quality depends on depends on influences influences User Acceptance Unit tests tests tests Source: ISO/IEC SQuaRE 25000
  2. FEEDBACK LOOP Write a failing acceptance test Write a failing

    unit test Make the test pass Refactor Source: Growing Object-Oriented Software, Guided by Tests, Steve Freeman and Nat Pryce
  3. Show payment method in invoice INSIDE-OUT TESTING Show payment method

    in invoice mail Show payment method in invoice web view Story Convert story to acceptance criteria Acceptance Criteria Convert acceptance criteria to acceptance tests describe "Subscribe and pay for Premium" it "should show payment method in invoice mail" do subscribe_to_premium_and_pay(user, :pay_with => "Visa") current_email.should have_body_text("Visa") end it "should show payment method in invoice web view" visit invoice_path page.should have_content("Visa") end end Acceptance Tests Unit Tests Create unit tests where appropriate describe "Invoice" it "should have payment method" do user = stub("User") subscription = stub("Subscription") invoice = create_invoice(user, subscription, :pay_with => "Visa") invoice.payment_method.should == "Visa" end end
  4. NAMING CONVENTIONS • Acceptance Testing: Formal testing with respect to

    user needs, requirements, and business processes [...] to determine whether or not to accept the system. [After IEEE 610] • Integration Testing: Testing performed to expose defects in the interfaces and in the interactions between integrated components or systems. • Unit Test: The testing of individual software components. [After IEEE 610] Source: International Software Testing Qualifications Board, Glossary of Testing Terms, www.istqb.org
  5. ACCEPTANCE TEST • Blackbox: In a web app, request and

    response is all we have • Test common use cases without getting to low level in your assertions • No mocks or stubs • Test invokes entire stack including web framework, databases, caches, etc.
  6. UNIT TEST • Whitebox: Control and see everything • Used

    primarily as a helper for the developer (to drive the design of SUT) • Used in bugfixes to simulate the bug and afterwards as a regression test • Mock and stub collaborators of SUT
  7. DEFAULT RAILS TEST FOLDER STRUCTURE • functional • integration •

    performance • unit • acceptance • performance • unit • models • controllers • views
  8. SOURCES • Growing Object-Oriented Software, Guided by Tests - Steve

    Freeman and Nat Pryce • ISO/IEC 25010 SQuaRE (successor to ISO 9126)