behaviour driven development present

32
Behaviour Driven Development with using Cucumber and Rspec By Rahul Panjiyar

Upload: raul-panjiyar

Post on 10-Jun-2015

5.071 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Behaviour driven development present

Behaviour Driven Development

with using Cucumber and RspecBy Rahul Panjiyar

Page 2: Behaviour driven development present

What is BDD?

• Increase collaboration • Test Driven• Outside-in*• Natural Language• What you were thinking and what you were

trying to achieve?

Page 3: Behaviour driven development present

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.

Page 4: Behaviour driven development present

Outside-in

• Satisfy the needs of stakeholders• Speak in natural language• Test in natural language• Red- Green- Refactor*

Page 5: Behaviour driven development present

The Perfect Suite

• Cucumber• BDD Acceptance Testing Framework• RSpec• BDD Unit Testing Framework

Page 6: Behaviour driven development present

Cucumber

• Users plain text to convey test cases• Speak & address to stakeholders needs• Automate functional validation • Executable specifications • Living Documentation

Page 7: Behaviour driven development present

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

Page 8: Behaviour driven development present
Page 9: Behaviour driven development present
Page 10: Behaviour driven development present

Using Cucumber with other platforms

Platform Tools

Frank

Cuke4AS3

Cuke4PHP

Cucumber-js

SpecFlow

Cucumber-jvm

CukeBins

Page 11: Behaviour driven development present

Cucumber code

• Typical Feature DescriptionIn order to <gain business value>As a <role>I want to <perform an action>

• Typical Test ScenarioGiven <some context>When I <perform some action>Then I should <observe expected outcome>

Page 12: Behaviour driven development present

Cucumber in the real world

• One feature summary per file<Role> <Performs action>

• Feature: User Submits blog postIn order to share my thoughts with the worldAs a blog authorI want to post to my blog

• Multiple scenarios (Test Cases) per feature• Exercise entire application stack• Write from stakeholders perspective

Page 13: Behaviour driven development present

Contd..

Scenario: Submit valid blog post Given I am on the blog pageWhen 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 pageAnd I should see “My first post”

Page 14: Behaviour driven development present

Cucumber step definitions

• Maps test code to plain text stepsGiven I am on the new post pageGiven /^I am on the (.+)$/ do |page_name| visit path_to(page_name)end

Page 15: Behaviour driven development present

RSpec

• Unit tests in plain English• Integrated mocking and stubbing framework• Plays nice with Test::Unit

Page 16: Behaviour driven development present

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

Page 17: Behaviour driven development present

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

Page 18: Behaviour driven development present

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

Page 19: Behaviour driven development present

$ gem install cucumber

Page 20: Behaviour driven development present

$ rails generate cucumber:install$ rails generate rspec:install

Page 21: Behaviour driven development present

Rakefile

require ‘rubygems’ require ‘cucumber/rake/task’

Cucumber::Rake::Task.new

Page 22: Behaviour driven development present

$ 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”

Page 23: Behaviour driven development present
Page 24: Behaviour driven development present

features/ companies.feature steps/ company_steps.rb

Page 25: Behaviour driven development present

Given == Setup

Page 26: Behaviour driven development present
Page 27: Behaviour driven development present
Page 28: Behaviour driven development present

When == Change

Page 29: Behaviour driven development present

When == Change

Page 30: Behaviour driven development present

Then == Outcome

Page 31: Behaviour driven development present
Page 32: Behaviour driven development present

THANK YOU