SlideShare a Scribd company logo
Behaviour Driven
Development
with using Cucumber and Rspec
By Rahul Panjiyar
What is BDD?
•   Increase collaboration
•   Test Driven
•   Outside-in*
•   Natural Language
•   What you were thinking and what you were
    trying to achieve?
Why Test?
•   ‘The bigger they come, the harder they fall’.
•   Easier to debug
•   Better understanding of requirements
•   More flexible
•   A bug is not an error in logic, it is a test you
    forget to write.
Outside-in
•   Satisfy the needs of stakeholders
•   Speak in natural language
•   Test in natural language
•   Red- Green- Refactor*
The Perfect Suite
• Cucumber
 • BDD Acceptance Testing Framework
• RSpec
 • BDD Unit Testing Framework
Cucumber
•   Users plain text to convey test cases
•   Speak & address to stakeholders needs
•   Automate functional validation
•   Executable specifications
•   Living Documentation
Why use Cucumber?
• Easy to setup*
• Supports multiple report formats
• Supports different ways of describing
  executable specifications
• Supports writing specifications in about 40
  spoken languages
• Web testing libraries
Behaviour driven development present
Behaviour driven development present
Using Cucumber with other platforms

     Platform     Tools

                  Frank


                  Cuke4AS3


                  Cuke4PHP

                  Cucumber-js

                  SpecFlow

                  Cucumber-jvm

                  CukeBins
Cucumber code
• Typical Feature Description
  In order to <gain business value>
  As a <role>
  I want to <perform an action>
• Typical Test Scenario
  Given <some context>
  When I <perform some action>
  Then I should <observe expected outcome>
Cucumber in the real world
• One feature summary per file
   <Role> <Performs action>
• Feature: User Submits blog post
   In order to share my thoughts with the world
   As a blog author
   I want to post to my blog
• Multiple scenarios (Test Cases) per feature
• Exercise entire application stack
• Write from stakeholders perspective
Contd..
Scenario: Submit valid blog post
  Given I am on the blog page
  When I fill in “title” with “My first post”
  And I fill “body” with “Test page”
  And I press “submit”
  Then I should be on the blog page
  And I should see “My first post”
Cucumber step definitions
• Maps test code to plain text steps
  Given I am on the new post page
  Given /^I am on the (.+)$/ do |page_name|
  visit path_to(page_name)
  end
RSpec
• Unit tests in plain English
• Integrated mocking and stubbing framework
• Plays nice with Test::Unit
RSpec By Example
 describe “guess” do
  it "sends the mark to output" do
  game.start('1234')
  output.should_receive(:puts).with('++++')
  game.guess('1234')
 end
Red Green Refactor
• Get to Red
   Write your test First!
   Use the code you Wish You Had
   Run the suite and watch your test fail
• Get to Green
   Write your implementation code
   Run the site and watch it pass
• Refactor
   Look for opportunities to improve your code
   Run the tests again, you should see still see Green
R G R in practice
• From cucumber
    Write your scenario
    Get to Red
• Drill down into Rspec
    Red-Green-Refactor
• Back up to Cucumber
    Get to Green
$ gem install cucumber
$ rails generate cucumber:install
$ rails generate rspec:install
Rakefile
require ‘rubygems’
require ‘cucumber/rake/task’

Cucumber::Rake::Task.new
$ cucumber --i18n help
$ cucumber –i18n pt
#language: pt
   Cenário: Realizar uma pesquisa
      Dado que acessei o site “http://www.google.com.br”
      Quando eu informar o texto “ele é um fofo” no
   campo de busca.
      E acionar o botao Pesquisa Google
      Então a lista de resultados deve conter o texto
   “todateen.uol.com.br/garotastt/ele-e-fofo-mas-nao-e-
   bonito-vale-a-pena-dar-uma-chance-pra-ele”
Behaviour driven development present
features/
 companies.feature
  steps/
   company_steps.rb
Given == Setup
Behaviour driven development present
Behaviour driven development present
When == Change
When == Change
Then == Outcome
Behaviour driven development present
THANK YOU

More Related Content

What's hot (20)

PPT
Coffee script final
priyankazope
 
PDF
DDD with Behat
Anton Serdyuk
 
PDF
Performance
Derek Kraan
 
PDF
BDD with the Cucumber
Mücahit Kurt
 
PDF
Slim PHP when you don't need the kitchen sink
Joe Ferguson
 
PPTX
PowerShell: Automation for everyone
Gavin Barron
 
PPTX
Zero to Testing in JavaScript
pamselle
 
PPTX
MidwestJS Zero to Testing
pamselle
 
PDF
Ruby on rails rspec
Bindesh Vijayan
 
PDF
Tested and Correct, How to Make Sure Your Documentation Keeps Working
Adam Dangoor
 
PDF
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Bruce Li
 
PDF
Modern infrastructure as code with ansible cake fest 2021
Joe Ferguson
 
PDF
Modern infrastructure as code with ansible PyTN
Joe Ferguson
 
PDF
Taking Your Rails Tests Offline
Joshua Plicque
 
PDF
Refactoring Workshop (Rails Pacific 2014)
Bruce Li
 
PPTX
Day 1 - Intro to Ruby
Barry Jones
 
PPTX
Hands on Gradle
Mushfekur Rahman
 
PDF
Another pair of eyes
Adam Dangoor
 
PPTX
Real Life Test Maintenance
Gil Zilberfeld
 
PPTX
Automating JavaScript testing with Jasmine and Perl
nohuhu
 
Coffee script final
priyankazope
 
DDD with Behat
Anton Serdyuk
 
Performance
Derek Kraan
 
BDD with the Cucumber
Mücahit Kurt
 
Slim PHP when you don't need the kitchen sink
Joe Ferguson
 
PowerShell: Automation for everyone
Gavin Barron
 
Zero to Testing in JavaScript
pamselle
 
MidwestJS Zero to Testing
pamselle
 
Ruby on rails rspec
Bindesh Vijayan
 
Tested and Correct, How to Make Sure Your Documentation Keeps Working
Adam Dangoor
 
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Bruce Li
 
Modern infrastructure as code with ansible cake fest 2021
Joe Ferguson
 
Modern infrastructure as code with ansible PyTN
Joe Ferguson
 
Taking Your Rails Tests Offline
Joshua Plicque
 
Refactoring Workshop (Rails Pacific 2014)
Bruce Li
 
Day 1 - Intro to Ruby
Barry Jones
 
Hands on Gradle
Mushfekur Rahman
 
Another pair of eyes
Adam Dangoor
 
Real Life Test Maintenance
Gil Zilberfeld
 
Automating JavaScript testing with Jasmine and Perl
nohuhu
 

Similar to Behaviour driven development present (20)

PDF
Cucumber & BDD
Sam Davarnia
 
PDF
BDD API Tests with Gherkin and Behat
Mark Niebergall
 
PPTX
Introduction to Test Driven Development
Sarah Dutkiewicz
 
PDF
Behaviour driven infrastructure
Lindsay Holmwood
 
PDF
Rspec and Capybara Intro Tutorial at RailsConf 2013
Brian Sam-Bodden
 
PDF
Jest: Frontend Testing leicht gemacht @EnterJS2018
Holger Grosse-Plankermann
 
PDF
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Holger Grosse-Plankermann
 
KEY
Cucumber
Michael MacDonald
 
PPTX
Cucumber presenation
Oussama BEN WAFI
 
PPTX
Cucumber_Training_ForQA
Meenakshi Singhal
 
PDF
BDD API Tests with Gherkin and Behat
Mark Niebergall
 
PDF
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
Ortus Solutions, Corp
 
PDF
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Holger Grosse-Plankermann
 
PDF
Quick tour to front end unit testing using jasmine
Gil Fink
 
PPTX
Intro to TDD and BDD
Jason Noble
 
ODP
2014 11 20 Drupal 7 -> 8 test migratie
hcderaad
 
PPTX
Behavior Driven Development - TdT@Cluj #15
Tabăra de Testare
 
PDF
Designing REST APIs
Srikanth Sombhatla
 
PPTX
BDD / cucumber /Capybara
ShraddhaSF
 
PPTX
Introduction to Testing and TDD
Sarah Dutkiewicz
 
Cucumber & BDD
Sam Davarnia
 
BDD API Tests with Gherkin and Behat
Mark Niebergall
 
Introduction to Test Driven Development
Sarah Dutkiewicz
 
Behaviour driven infrastructure
Lindsay Holmwood
 
Rspec and Capybara Intro Tutorial at RailsConf 2013
Brian Sam-Bodden
 
Jest: Frontend Testing leicht gemacht @EnterJS2018
Holger Grosse-Plankermann
 
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Holger Grosse-Plankermann
 
Cucumber presenation
Oussama BEN WAFI
 
Cucumber_Training_ForQA
Meenakshi Singhal
 
BDD API Tests with Gherkin and Behat
Mark Niebergall
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
Ortus Solutions, Corp
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Holger Grosse-Plankermann
 
Quick tour to front end unit testing using jasmine
Gil Fink
 
Intro to TDD and BDD
Jason Noble
 
2014 11 20 Drupal 7 -> 8 test migratie
hcderaad
 
Behavior Driven Development - TdT@Cluj #15
Tabăra de Testare
 
Designing REST APIs
Srikanth Sombhatla
 
BDD / cucumber /Capybara
ShraddhaSF
 
Introduction to Testing and TDD
Sarah Dutkiewicz
 
Ad

Behaviour driven development present

  • 1. Behaviour Driven Development with using Cucumber and Rspec By Rahul Panjiyar
  • 2. What is BDD? • Increase collaboration • Test Driven • Outside-in* • Natural Language • What you were thinking and what you were trying to achieve?
  • 3. Why Test? • ‘The bigger they come, the harder they fall’. • Easier to debug • Better understanding of requirements • More flexible • A bug is not an error in logic, it is a test you forget to write.
  • 4. Outside-in • Satisfy the needs of stakeholders • Speak in natural language • Test in natural language • Red- Green- Refactor*
  • 5. The Perfect Suite • Cucumber • BDD Acceptance Testing Framework • RSpec • BDD Unit Testing Framework
  • 6. Cucumber • Users plain text to convey test cases • Speak & address to stakeholders needs • Automate functional validation • Executable specifications • Living Documentation
  • 7. Why use Cucumber? • Easy to setup* • Supports multiple report formats • Supports different ways of describing executable specifications • Supports writing specifications in about 40 spoken languages • Web testing libraries
  • 10. Using Cucumber with other platforms Platform Tools Frank Cuke4AS3 Cuke4PHP Cucumber-js SpecFlow Cucumber-jvm CukeBins
  • 11. Cucumber code • Typical Feature Description In order to <gain business value> As a <role> I want to <perform an action> • Typical Test Scenario Given <some context> When I <perform some action> Then I should <observe expected outcome>
  • 12. Cucumber in the real world • One feature summary per file <Role> <Performs action> • Feature: User Submits blog post In order to share my thoughts with the world As a blog author I want to post to my blog • Multiple scenarios (Test Cases) per feature • Exercise entire application stack • Write from stakeholders perspective
  • 13. Contd.. Scenario: Submit valid blog post Given I am on the blog page When I fill in “title” with “My first post” And I fill “body” with “Test page” And I press “submit” Then I should be on the blog page And I should see “My first post”
  • 14. Cucumber step definitions • Maps test code to plain text steps Given I am on the new post page Given /^I am on the (.+)$/ do |page_name| visit path_to(page_name) end
  • 15. RSpec • Unit tests in plain English • Integrated mocking and stubbing framework • Plays nice with Test::Unit
  • 16. RSpec By Example describe “guess” do it "sends the mark to output" do game.start('1234') output.should_receive(:puts).with('++++') game.guess('1234') end
  • 17. Red Green Refactor • Get to Red  Write your test First!  Use the code you Wish You Had  Run the suite and watch your test fail • Get to Green  Write your implementation code  Run the site and watch it pass • Refactor  Look for opportunities to improve your code  Run the tests again, you should see still see Green
  • 18. R G R in practice • From cucumber  Write your scenario  Get to Red • Drill down into Rspec  Red-Green-Refactor • Back up to Cucumber  Get to Green
  • 19. $ gem install cucumber
  • 20. $ rails generate cucumber:install $ rails generate rspec:install
  • 22. $ cucumber --i18n help $ cucumber –i18n pt #language: pt Cenário: Realizar uma pesquisa Dado que acessei o site “http://www.google.com.br” Quando eu informar o texto “ele é um fofo” no campo de busca. E acionar o botao Pesquisa Google Então a lista de resultados deve conter o texto “todateen.uol.com.br/garotastt/ele-e-fofo-mas-nao-e- bonito-vale-a-pena-dar-uma-chance-pra-ele”
  • 24. features/ companies.feature steps/ company_steps.rb