Slide 1

Slide 1 text

TESTING BEST PRACTICES SEIT 2012 @hurx github.com/elitau

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Unit Amount of feedback Internal quality External quality Integration Acceptance Test Level

Slide 4

Slide 4 text

Unit Execution Time Integration Acceptance Test Level Not Automated

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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.

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

DEFAULT RAILS TEST FOLDER STRUCTURE • functional • integration • performance • unit • acceptance • performance • unit • models • controllers • views

Slide 11

Slide 11 text

SOURCES • Growing Object-Oriented Software, Guided by Tests - Steve Freeman and Nat Pryce • ISO/IEC 25010 SQuaRE (successor to ISO 9126)