ݺߣ

ݺߣShare a Scribd company logo
Integration Test
 with Cucumber and Webrat




     Kang-min Liu
   gugod@gugod.org
Integration Test

?
?
? Web App:
: twitter
Integration Test With Cucumber And Webrat
Integration Test With Cucumber And Webrat
Integration Test With Cucumber And Webrat
: twitter

1.            http://twitter.com/home

2.     status

3.   update

4.
Webrat

visit "http://twitter.com/home"
fill_in "status", :with => "lorem ipsum"
click_button "update"

response.body.should =~ /lorem ipsum/
Webrat
Browser emulation / control
Webrat

?
?
?
?
Webrat


?   javascript

?   css
Webrat

?
    ? Selenium
    ? Watir
Webrat Core API
?   visit        ?   select

?   click_link   ?   attach_?le

?   ?ll_in       ?   click_button

?   check

?   uncheck

?   choose
Webrat Core API

? visit, click_link
 ? get + assert_response :success
? click_button
 ? submit form + assert_response :success
 ? submit form default values if any
Webrat + RSpec
describe "tweeting" do
  it "should show my tweets" do
    visit "/home"
    fill_in "status", :with => "lorem ipsum"
    click_button "update"
    response.body.should =~ /lorem ipsum/
  end
end
?
Goods

?
?    HTML

?
Cucumber

? BDD (Behavior Driven Development) Tool
? Ruby implementation
?
?
Feature: Update my status
  In order to keep friends posted
  As a friendly person
  I post my status to twitter

  Scenario: Update my status
    Given I go to /home
    When I fill in status with lorem ipsum
    And I click send
    Then I should see lorem ipsum
Feature: Update my status
  In order to keep friends posted
  As a friendly person
  I post my status to twitter

  Scenario: Update my status
    Given I go to /home
    When I fill in status with lorem ipsum
    And I click send
    Then I should see lorem ipsum
Feature: Update my status
  In order to keep friends posted
  As a friendly person
  I post my status to twitter

  Scenario: Update my status
    Given I go to /home
    When I fill in status with lorem ipsum
    And I click send
    Then I should see lorem ipsum
Scenario: Update my status
   Given I go to /home
   When I fill in status with lorem ipsum
   And I click send
   Then I should see lorem ipsum

Given C
When C
Then C
Given /^I go to "(.*)"$/ do |url|
  visit url
end

When /^I fill in "(.*)" with "(.*)"$/ do |field,value|
  fill_in field, :with => value
end

When /^I click "(.*)"$/ do |link|
  click_link(link)
end

Then /^I should see "(.*)"$/ do |text|
  response.body.should =~ /#{text}/m
end
?
Goods...
?

?
    ?
    ?
Goods...


?
    ?
Scenario: Update my status
  Given I go to /home
  When I fill in status with lorem ipsum
  And I click send
  Then I should see lorem ipsum
describe "tweeting" do
  it "should show my tweets" do
    visit "/home"
    fill_in "status", :with => "lorem ipsum"
    click_button "update"
    response.body.should =~ /lorem ipsum/
  end
end
Reference

? Cucumber http://cukes.info/
? Webrat http://github.com/brynary/webrat/
  tree/master
? Test::Cukes http://search.cpan.org/dist/Test-
  Cukes/ (Perl implementation)

More Related Content

Integration Test With Cucumber And Webrat

  • 1. Integration Test with Cucumber and Webrat Kang-min Liu gugod@gugod.org
  • 7. : twitter 1. http://twitter.com/home 2. status 3. update 4.
  • 8. Webrat visit "http://twitter.com/home" fill_in "status", :with => "lorem ipsum" click_button "update" response.body.should =~ /lorem ipsum/
  • 11. Webrat ? javascript ? css
  • 12. Webrat ? ? Selenium ? Watir
  • 13. Webrat Core API ? visit ? select ? click_link ? attach_?le ? ?ll_in ? click_button ? check ? uncheck ? choose
  • 14. Webrat Core API ? visit, click_link ? get + assert_response :success ? click_button ? submit form + assert_response :success ? submit form default values if any
  • 15. Webrat + RSpec describe "tweeting" do it "should show my tweets" do visit "/home" fill_in "status", :with => "lorem ipsum" click_button "update" response.body.should =~ /lorem ipsum/ end end
  • 16. ?
  • 17. Goods ? ? HTML ?
  • 18. Cucumber ? BDD (Behavior Driven Development) Tool ? Ruby implementation ? ?
  • 19. Feature: Update my status In order to keep friends posted As a friendly person I post my status to twitter Scenario: Update my status Given I go to /home When I fill in status with lorem ipsum And I click send Then I should see lorem ipsum
  • 20. Feature: Update my status In order to keep friends posted As a friendly person I post my status to twitter Scenario: Update my status Given I go to /home When I fill in status with lorem ipsum And I click send Then I should see lorem ipsum
  • 21. Feature: Update my status In order to keep friends posted As a friendly person I post my status to twitter Scenario: Update my status Given I go to /home When I fill in status with lorem ipsum And I click send Then I should see lorem ipsum
  • 22. Scenario: Update my status Given I go to /home When I fill in status with lorem ipsum And I click send Then I should see lorem ipsum Given C When C Then C
  • 23. Given /^I go to "(.*)"$/ do |url| visit url end When /^I fill in "(.*)" with "(.*)"$/ do |field,value| fill_in field, :with => value end When /^I click "(.*)"$/ do |link| click_link(link) end Then /^I should see "(.*)"$/ do |text| response.body.should =~ /#{text}/m end
  • 24. ?
  • 27. Scenario: Update my status Given I go to /home When I fill in status with lorem ipsum And I click send Then I should see lorem ipsum
  • 28. describe "tweeting" do it "should show my tweets" do visit "/home" fill_in "status", :with => "lorem ipsum" click_button "update" response.body.should =~ /lorem ipsum/ end end
  • 29. Reference ? Cucumber http://cukes.info/ ? Webrat http://github.com/brynary/webrat/ tree/master ? Test::Cukes http://search.cpan.org/dist/Test- Cukes/ (Perl implementation)