Acceptance Testing

Pawel Pierzchala @zwrozka

Top-down testing

customer

Risk of bottom-up design

designer

Can be shown early

complex ui

Role of acceptance test

Smoke test

smoke test

Feedback cycles

  • Acceptance ~ minutes
  • Integration ~ seconds
  • Unit ~ milliseconds

Testing pyramid

pyramid

How to write good acceptance tests?

Imperative vs Declartive


page.click_button "Login"
page.should have_content("Welcome, jack@daniles.com!")
          

vs


And I click "Login" button
Then I should see "Welcome, jack@daniles.com!"
          

Abstract


login_page.open
login_page.login("jack@daniels.com", "sardines")
login_page.should_be_logged_as("jack@daniels.com")
          

Page object


class LoginPage < Page
  def open
    visit '/login'
  end

  def login(email, password)
    fill_in "Email", with: email
    fill_in "Password", with: password
    click_button "Login"
  end

  def should_be_logged_as(email)
    within(".navbar") do
      page.should have_content(email)
    end
  end
end
          

Page object for a fragment


class TweetPage < Page
  def initialize(tweet)
    @tweet = tweet
  end

  def retweet
    within("tweet-{@tweet.id}") do
      click_button("Retweet")
    end
  end
end
          

End to End

From keyboard to API

From API to DB

capybara

feature "Adding messages to timeline" do
  scenario "adding a message to a friend timeline" do
    timeline.open("joe")

    timeline.add_message("I like cats")

    timeline.should have_message("I like cats")
  end
end
          

rack-test vs headless

poltergeist

PhanotmJS

Red Green Refactor?

Switch roles often

Exercise

Blog 2.0

github.com/wrozka/blog

Posting is already implemented

It needs comments and ratings

Focus on acceptance test, create a new page object

Implement as little as possible