Cucumber

ihower@handlino.com
about me
    •              (a.k.a ihower)
        http://ihower.idv.tw/blog/



•
             http://handlino.com
           http://registrano.com
Q:
 In order ...
 As a COSCUP 2009 attendee
 I want ...
Q:
 In order ... [business value]
 As a COSCUP 2009 attendee [role]
 I want ... [feature]
?
What’s your acceptance criteria?
Scenario:     COSCUP 2009

Given
When ihower
Then
And
“I believe that the hardest part of software projects, the
most common source of project failure, is
communication with the customers and users of that
software.

By providing a clear yet precise language to deal with
domains, a DSL can help improve this communication.”

                                           Martin Fowler
“


            (DSL)
    ”
        Martin Fowler
(DSL)

?
Cucumber




               Ruby
     Feature
Cucumber Feature
    Feature:




{
    Scenario:
     Given <            >
     And <          >
     When <     >
     And <      >
     Then <          >
     And <          >
Given




Given /^             (.*)$/ do |fruit|
    #.... your test code
    assert_equal(fruit, '      ')
end
             Ruby
Given




Given /^             (.*)$/ do |fruit|
    #.... your test code
    assert_equal(fruit, '      ')
end
             Ruby
Given



                      Regexp match

Given /^             (.*)$/ do |fruit|
    #.... your test code
    assert_equal(fruit, '      ')
end
             Ruby
Cucumber
• Ruby and Rails
• JRuby and Java
• IronRuby and .NET
• FunFX and Flex
• Web apps in any lanuages, with:
 • Watir, Selenium, Mechanize, Webrat
Cucumber огурец Russian
       concombre French
                  Japanese
        Okurkový Czech
         Gurke German
        Cucumber English
         pepino Spanish
                             !! Korean
         cetriolo Italian
                             gurka Swedish
           agurk Danish
                             castravete Romanian
            Arabic ‫ﺍﳋﻴﺎﺭ‬
                             ogórek Polish
       ketimun Indonesian
                             Kurk Estonian
         Hebrew ‫מְלָפְפֹון‬
                             dưa chuột Vietnamese
       Cogombre Catalan
                             uhorka Slovak
     CUCUMBR LOLCats
                             gurķis Latvian
        Agurk Norwegian
                             Agurkas Lithuanian
       黄 !! Korean
                             Salátauborka Hungarian
          gurka Swedish
                             Kurkku Finnish
      castravete Romanian
                             Краставица Bulgarian
          ogórek Polish
                             Pepino Portuguese
          Kurk Estonian
     dưa chuột Vietnamese
          uhorka Slovak
          gurķis Latvian
       Agurkas Lithuanian
    Salátauborka Hungarian
         Kurkku Finnish
     Краставица Bulgarian
       Pepino Portuguese
Feature
   :
  
  
  
 
     :
                        3
                        2
         divide
                  1.5
Ruby code
Given /                 (d+)/ do |n|
  @calc.push n.to_i
end

When /      (w+)/ do |op|
  @result = @calc.send op
end

Then /             (.*)/ do |result|
  @result.should == result.to_f
end
Web Integration Testing
Feature:

 Scenario:
  Given I am on the "1934356085" book page
  When I press "Add to Cart"
  Then I should see "Programming Ruby 1.9"
Ruby Code

Given /^I am on (.+)$/ do |page_name|
  visit path_to(page_name)
end

When /^I press "([^"]*)"$/ do |button|
  click_button(button)
end

Then /^I should see "([^"]*)"$/ do |text|
  response.should contain(text)
end
Ruby Code

Given /^I am on (.+)$/ do |page_name|
  visit path_to(page_name)
end

When /^I press "([^"]*)"$/ do |button|
  click_button(button)
end

Then /^I should see "([^"]*)"$/ do |text|
  response.should contain(text)
end
{
              1:
              2:          Ruby
Outside
              3:                 (fail)
              4.                            (pass)

     Inside   {    4-1.
                   4-2
                             Unit Test    (Fail)
                                            (Pass)
thank you.
http://cukes.info/

Cucumber: 小黃瓜驗收測試工具

  • 1.
  • 2.
    about me • (a.k.a ihower) http://ihower.idv.tw/blog/ • http://handlino.com http://registrano.com
  • 3.
    Q: In order... As a COSCUP 2009 attendee I want ...
  • 4.
    Q: In order... [business value] As a COSCUP 2009 attendee [role] I want ... [feature]
  • 5.
  • 6.
    Scenario: COSCUP 2009 Given When ihower Then And
  • 7.
    “I believe thatthe hardest part of software projects, the most common source of project failure, is communication with the customers and users of that software. By providing a clear yet precise language to deal with domains, a DSL can help improve this communication.” Martin Fowler
  • 8.
    (DSL) ” Martin Fowler
  • 9.
  • 10.
    Cucumber Ruby Feature
  • 11.
    Cucumber Feature Feature: { Scenario: Given < > And < > When < > And < > Then < > And < >
  • 12.
    Given Given /^ (.*)$/ do |fruit| #.... your test code assert_equal(fruit, ' ') end Ruby
  • 13.
    Given Given /^ (.*)$/ do |fruit| #.... your test code assert_equal(fruit, ' ') end Ruby
  • 14.
    Given Regexp match Given /^ (.*)$/ do |fruit| #.... your test code assert_equal(fruit, ' ') end Ruby
  • 15.
    Cucumber • Ruby andRails • JRuby and Java • IronRuby and .NET • FunFX and Flex • Web apps in any lanuages, with: • Watir, Selenium, Mechanize, Webrat
  • 16.
    Cucumber огурец Russian concombre French Japanese Okurkový Czech Gurke German Cucumber English pepino Spanish !! Korean cetriolo Italian gurka Swedish agurk Danish castravete Romanian Arabic ‫ﺍﳋﻴﺎﺭ‬ ogórek Polish ketimun Indonesian Kurk Estonian Hebrew ‫מְלָפְפֹון‬ dưa chuột Vietnamese Cogombre Catalan uhorka Slovak CUCUMBR LOLCats gurķis Latvian Agurk Norwegian Agurkas Lithuanian 黄 !! Korean Salátauborka Hungarian gurka Swedish Kurkku Finnish castravete Romanian Краставица Bulgarian ogórek Polish Pepino Portuguese Kurk Estonian dưa chuột Vietnamese uhorka Slovak gurķis Latvian Agurkas Lithuanian Salátauborka Hungarian Kurkku Finnish Краставица Bulgarian Pepino Portuguese
  • 18.
    Feature :               :      3      2      divide      1.5
  • 19.
    Ruby code Given / (d+)/ do |n| @calc.push n.to_i end When / (w+)/ do |op| @result = @calc.send op end Then / (.*)/ do |result| @result.should == result.to_f end
  • 20.
  • 21.
    Feature: Scenario: Given I am on the "1934356085" book page When I press "Add to Cart" Then I should see "Programming Ruby 1.9"
  • 22.
    Ruby Code Given /^Iam on (.+)$/ do |page_name| visit path_to(page_name) end When /^I press "([^"]*)"$/ do |button| click_button(button) end Then /^I should see "([^"]*)"$/ do |text| response.should contain(text) end
  • 23.
    Ruby Code Given /^Iam on (.+)$/ do |page_name| visit path_to(page_name) end When /^I press "([^"]*)"$/ do |button| click_button(button) end Then /^I should see "([^"]*)"$/ do |text| response.should contain(text) end
  • 24.
    { 1: 2: Ruby Outside 3: (fail) 4. (pass) Inside { 4-1. 4-2 Unit Test (Fail) (Pass)
  • 25.