SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Why should we use automatic
      test framework?
A long long story…
Why should we choose
                ?
Test Driven Development
cCan you understand it?

       No, I can’t
Behavior Driven Development
Feature:

Now User has given all his basic info and decided which products he will buy, then he
forward into the last process - pay the money. /registration/business_pay will summarize the
price(including tax and discount) he will pay and let user fill in his credit card info, when he
presses "Confirm", it will charge his credit card.

Scenario: Now user input credit card info and press "Confirm", the page will submit his info
to AriaSystem, AriaSystem will validate his credit card info, charge his credit card and return
some data to our database. Then our database will save his personal info and partner info. If
all these work well, user will be redirected to /registration/business_finish.

  Given I reach /registration/business_pay
  When I fill in basic info into /registration/business_pay
  And I press "Confirm"
  Then I should see "Please wait..."
  And I waiting for being redirected to "/registration/business_finish"
  And all MozyPro data in Database is correct
Everyone can read it
Everyone can write it

Include people who don’t speak English
How does it test?
Open a real browser
Behave as a real user
Apply to any page, any website
Not only BDD
But also DDD

Document Driven Development
Cucumber Style Document
More secrets ?
Step Definitions
Given /^I am in "([^"]*)"$/ do |url|
   visit mozy_url(url, :https => true)
end

Then /^I would be redirected to "([^"]*)"$/ do |url|
  page.current_url.should
be_include?mozy_url(url, :https => true)
end
Have a try ?

Let’s write a simple Cucumber test case
Sign up an Account
Gemfile
group :test do
 gem 'cucumber'
 gem 'cucumber-rails', require: false
 gem 'capybara', git: 'https://github.com/jnicklas/capybara.git'
 gem 'rspec'                     #use rspec expectation
 gem 'Selenium'                  #use firefox to test
 gem 'database_cleaner' #clean database after each test case
end

$ bundle install
Install Cucumber
$ rails generate cucumber:install
    create config/cucumber.yml
    create script/cucumber
     chmod script/cucumber
    create features/step_definitions
    create features/support
    create features/support/env.rb
     exist lib/tasks
    create lib/tasks/cucumber.rake
      gsub config/database.yml
      gsub config/database.yml
     force config/database.yml
features/support/env.rb
require 'cucumber/rails’

Capybara.default_selector = :css
Capybara.default_driver = :selenium           #add this line

ActionController::Base.allow_rescue = false

begin
 DatabaseCleaner.strategy = :transaction
rescue NameError
 raise "You need to add database_cleaner to your Gemfile (in the :test group) if you
wish to use it."
End

Cucumber::Rails::Database.javascript_strategy = :truncation
features/sign_up.feature
Feature: Sign up

 Scenario: I will register a user with email "zhour@vmware.com" and
password "vmware”

  Given I fill in email "zhour@vmware.com" and password "vmware" in sign
up page
  When I press "Sign up"
  Then I should see "Page#index"
$ rake cucumber
features/step_definitions/sign_up.rb
it works
Firefox
Thanks

Weitere ähnliche Inhalte

Was ist angesagt?

The Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsThe Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web apps
John Anderson
 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)
Thinkful
 

Was ist angesagt? (20)

CoffeeScript Design Patterns
CoffeeScript Design PatternsCoffeeScript Design Patterns
CoffeeScript Design Patterns
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overview
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 
Automated Testing with Ruby
Automated Testing with RubyAutomated Testing with Ruby
Automated Testing with Ruby
 
Why Use Rails by Dr Nic
Why Use Rails by  Dr NicWhy Use Rails by  Dr Nic
Why Use Rails by Dr Nic
 
React basic by Yoav Amit, Wix
React basic by Yoav Amit, Wix React basic by Yoav Amit, Wix
React basic by Yoav Amit, Wix
 
End to-End CoffeeScript
End to-End CoffeeScriptEnd to-End CoffeeScript
End to-End CoffeeScript
 
Reacting to the Isomorphic Buzz
Reacting to the Isomorphic BuzzReacting to the Isomorphic Buzz
Reacting to the Isomorphic Buzz
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsAPIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page Objects
 
The Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsThe Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web apps
 
Type script for_java_dev_jul_2020
Type script for_java_dev_jul_2020Type script for_java_dev_jul_2020
Type script for_java_dev_jul_2020
 
From ActiveRecord to EventSourcing
From ActiveRecord to EventSourcingFrom ActiveRecord to EventSourcing
From ActiveRecord to EventSourcing
 
BDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
BDD to the Bone: Using Behave and Selenium to Test-Drive Web ApplicationsBDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
BDD to the Bone: Using Behave and Selenium to Test-Drive Web Applications
 
Modern Functional Fluent ColdFusion REST Apis
Modern Functional Fluent ColdFusion REST ApisModern Functional Fluent ColdFusion REST Apis
Modern Functional Fluent ColdFusion REST Apis
 
Creating A Vba Function Library For Use In QTP/VBSCRIPT
Creating A Vba Function Library For Use In QTP/VBSCRIPTCreating A Vba Function Library For Use In QTP/VBSCRIPT
Creating A Vba Function Library For Use In QTP/VBSCRIPT
 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)
 
Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)
 
2010 07-20 TDD with ActiveResource
2010 07-20 TDD with ActiveResource2010 07-20 TDD with ActiveResource
2010 07-20 TDD with ActiveResource
 
The WordPress REST API as a Springboard for Website Greatness
The WordPress REST API as a Springboard for Website GreatnessThe WordPress REST API as a Springboard for Website Greatness
The WordPress REST API as a Springboard for Website Greatness
 
Ninad cucumber rails
Ninad cucumber railsNinad cucumber rails
Ninad cucumber rails
 

Ähnlich wie Introduce cucumber

20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
Frank Rousseau
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
Jacob Kaplan-Moss
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
Jay Shirley
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
Justin Cataldo
 
Cis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry universityCis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry university
lhkslkdh89009
 
Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with Cucumber
Brandon Keepers
 

Ähnlich wie Introduce cucumber (20)

Transformando os pepinos do cliente no código de testes da sua aplicação
Transformando os pepinos do cliente no código de testes da sua aplicaçãoTransformando os pepinos do cliente no código de testes da sua aplicação
Transformando os pepinos do cliente no código de testes da sua aplicação
 
BDD / cucumber /Capybara
BDD / cucumber /CapybaraBDD / cucumber /Capybara
BDD / cucumber /Capybara
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with Cucumber
 
Behat - Drupal South 2018
Behat  - Drupal South 2018Behat  - Drupal South 2018
Behat - Drupal South 2018
 
Satchmo
SatchmoSatchmo
Satchmo
 
More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Libraries
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
Enabling agile devliery through enabling BDD in PHP projects
Enabling agile devliery through enabling BDD in PHP projectsEnabling agile devliery through enabling BDD in PHP projects
Enabling agile devliery through enabling BDD in PHP projects
 
How to convert custom plsql to web services-Soap OR Rest
How to convert custom plsql to web services-Soap OR RestHow to convert custom plsql to web services-Soap OR Rest
How to convert custom plsql to web services-Soap OR Rest
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
Devise and Rails
Devise and RailsDevise and Rails
Devise and Rails
 
Cis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry universityCis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry university
 
Single Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle StorySingle Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle Story
 
Testing C# and ASP.net using Ruby
Testing C# and ASP.net using RubyTesting C# and ASP.net using Ruby
Testing C# and ASP.net using Ruby
 
Behavioral Driven Development
Behavioral Driven Development Behavioral Driven Development
Behavioral Driven Development
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with Cucumber
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 

Introduce cucumber

  • 1.
  • 2. Why should we use automatic test framework?
  • 3. A long long story…
  • 4. Why should we choose ?
  • 6.
  • 7. cCan you understand it? No, I can’t
  • 9. Feature: Now User has given all his basic info and decided which products he will buy, then he forward into the last process - pay the money. /registration/business_pay will summarize the price(including tax and discount) he will pay and let user fill in his credit card info, when he presses "Confirm", it will charge his credit card. Scenario: Now user input credit card info and press "Confirm", the page will submit his info to AriaSystem, AriaSystem will validate his credit card info, charge his credit card and return some data to our database. Then our database will save his personal info and partner info. If all these work well, user will be redirected to /registration/business_finish. Given I reach /registration/business_pay When I fill in basic info into /registration/business_pay And I press "Confirm" Then I should see "Please wait..." And I waiting for being redirected to "/registration/business_finish" And all MozyPro data in Database is correct
  • 11. Everyone can write it Include people who don’t speak English
  • 12.
  • 13. How does it test?
  • 14. Open a real browser
  • 15. Behave as a real user
  • 16. Apply to any page, any website
  • 18. But also DDD Document Driven Development
  • 21. Step Definitions Given /^I am in "([^"]*)"$/ do |url| visit mozy_url(url, :https => true) end Then /^I would be redirected to "([^"]*)"$/ do |url| page.current_url.should be_include?mozy_url(url, :https => true) end
  • 22. Have a try ? Let’s write a simple Cucumber test case
  • 23. Sign up an Account
  • 24. Gemfile group :test do gem 'cucumber' gem 'cucumber-rails', require: false gem 'capybara', git: 'https://github.com/jnicklas/capybara.git' gem 'rspec' #use rspec expectation gem 'Selenium' #use firefox to test gem 'database_cleaner' #clean database after each test case end $ bundle install
  • 25. Install Cucumber $ rails generate cucumber:install create config/cucumber.yml create script/cucumber chmod script/cucumber create features/step_definitions create features/support create features/support/env.rb exist lib/tasks create lib/tasks/cucumber.rake gsub config/database.yml gsub config/database.yml force config/database.yml
  • 26. features/support/env.rb require 'cucumber/rails’ Capybara.default_selector = :css Capybara.default_driver = :selenium #add this line ActionController::Base.allow_rescue = false begin DatabaseCleaner.strategy = :transaction rescue NameError raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it." End Cucumber::Rails::Database.javascript_strategy = :truncation
  • 27. features/sign_up.feature Feature: Sign up Scenario: I will register a user with email "zhour@vmware.com" and password "vmware” Given I fill in email "zhour@vmware.com" and password "vmware" in sign up page When I press "Sign up" Then I should see "Page#index"