infosys confidential © 2012 © 2012. infosys limited. strictly private and confidential. no part of...
TRANSCRIPT
![Page 1: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/1.jpg)
Infosys Confidential © 2012© 2012. Infosys Limited. Strictly private and confidential. No part of this document should be
reproduced or distributed without the prior permission of Infosys Technologies Limited.
Agile BDD using RSpec and Cucumber
Aruna Banavar Shankar & Miti Bhat
![Page 2: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/2.jpg)
Infosys Confidential © 2012
Contents
• BDD• Installation• Demo for Rspec• Demo for Cucumber• The Basic Features• Cucumber vs. Rspec
2
![Page 3: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/3.jpg)
Infosys Confidential © 2012
A story
An elephant as seen by 6 blind people!
The elephant was assumed to be what was “felt” by these
blind peopleOne question! – Can everyone see one entity as it is???
3
![Page 4: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/4.jpg)
Infosys Confidential © 2012
Introduction to BDD
• “Getting the Words Right” is the focus of BDD, leading to building one language that is understood the same way by the project stakeholders
• Vision is to bring in consistency, accuracy and meaning • Behavior Driven Development (BDD) claims “the words you
use about something influence the way you think about that”.
4
![Page 5: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/5.jpg)
Infosys Confidential © 2012
How it works?
• As <a ROLE> I need a <FEATURE> towards <BENEFIT>• Examples
• As an <ADMIN> I need <ACCESS TO FUNCTIONAL ADMIN PORTAL> to <MANAGE USERS>
• As the <IT MANAGER> I need <DETAILED REPORT> to <VALIDATE IT SPEND>
5
![Page 6: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/6.jpg)
Infosys Confidential © 2012
Key stakeholders in a project
Different stakeholders, unlike mindset, varied mission come together in the project. Building an application by understanding its behavior from all stakeholder point of view. This builds a collaboration between developer, Tester, business andother teams.
Developer – -Interested in coding than testing-If tester finds a defect or if time permits …… focus on defects-Let me code first is the general tendency
Tester – -Primary responsibility is to test and find defects
Customer – -Clarifications, approvals, sign off
6
![Page 7: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/7.jpg)
Infosys Confidential © 2012
Then……what is BDD
In the "Agile specifications, BDD and Testing eXchange" in November 2009 in London, Dan North[3] gave the following description of BDD:
BDD is a second-generation, outside–in, pull-based, multiple-stakeholder, multiple-scale, high-automation, agile methodology. It describes a cycle of interactions with well-defined outputs, resulting in the delivery of working, tested software that matters.
7
![Page 8: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/8.jpg)
Infosys Confidential © 2012
About them…
• RSpec created by Steven Baker in 2005. • To explore new TDD frameworks• Encourage focus on behavior…. Rspec
• 2008, Aslak Hellesøy• To explore new BDD frameworks• Rewrites RSpec’s Story Runner with a real grammar…
Cucumber
8
![Page 9: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/9.jpg)
Infosys Confidential © 2012
Installation
• Installed as gems:
• rspec• cucumber
9
![Page 10: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/10.jpg)
Infosys Confidential © 2012
Folder Structure
http://www.sharpthoughts.org
10
![Page 11: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/11.jpg)
Infosys Confidential © 2012
Cucumber & RSpec
Ref: The Rspec Book by David Chelimsky and others published by The Pragmatic Bookshelf
11
![Page 12: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/12.jpg)
Infosys Confidential © 2012
Demo Hello Rspec
12
![Page 13: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/13.jpg)
Infosys Confidential © 2012
Demo: Hello Cucumber
13
![Page 14: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/14.jpg)
Infosys Confidential © 2012
Step Definitions
• Creates a step. • Methods:• Given( )• When( )• Then( )
• Each must have• Regexp• A block.
14
![Page 15: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/15.jpg)
Infosys Confidential © 2012
Step definitions Sample
• Given /^a greeter$/ do• @greeter = CucumberGreeter.new• end• When /^I send it the greet message$/ do• @message = @greeter.greet• end• Then /^I should see "([^"]*)"$/ do |greeting|• @message.should == greeting• end
15
![Page 16: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/16.jpg)
Infosys Confidential © 2012
Demo: step Definitions
website2
16
![Page 17: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/17.jpg)
Infosys Confidential © 2012
User stories
• Consider:
• User navigates to home page• User enters details• User successfully logs in• User unsuccessful in logging in
17
![Page 18: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/18.jpg)
Infosys Confidential © 2012
DEMO: Multiple scenarios
Website: adding more scenarios without tables
18
![Page 19: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/19.jpg)
Infosys Confidential © 2012
Scenario outlines
• Let us define a single scenario outline• Tables of input data• Expected output.
19
![Page 20: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/20.jpg)
Infosys Confidential © 2012
Sample: Scenario outlines
• Scenario Outline: submit guess• Given the secret code is "<code>"• When I guess "<guess>"• Then the symbol should be "<symbol>"
20
![Page 21: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/21.jpg)
Infosys Confidential © 2012
Sample: scenario Outlines
• Scenario Outline: submit details• Given the user name is "<uname>"• When I guess "<pwd>"• Then the message should be "<mesg>"
• Scenarios: no matches• | uname | pwd | symbol|• | ^^^^ | a1a1 | failed |
• Scenarios: 1 uname incorrect• | uname | pwd | mesg |• | abcd | 1555 | passed |• | ba-mn| 2555 | failed |
21
![Page 22: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/22.jpg)
Infosys Confidential © 2012
Test doubles
• An object that behaves as though it is the original object• Eg: output
22
![Page 23: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/23.jpg)
Infosys Confidential © 2012
Demo: Test Double
• Uses test double but shows logical error
23
![Page 24: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/24.jpg)
Infosys Confidential © 2012
“It” method
• The it( ) method:• creates an example• ExampleGroup returns an instance of it using describe( )
Demo: website5 Note: Rspec double(out) – a mock for STDOUT
24
![Page 25: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/25.jpg)
Infosys Confidential © 2012
A small change
• def start• @output.puts 'Welcome to website!'• end
• The test passes!!!
• Once the passing code is ready… See it in action!!!
• Demo: website6 using .bat file
25
![Page 26: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/26.jpg)
Infosys Confidential © 2012
When Cucumber & WHEN Rspec
• Cucumber - integration/acceptance testing• rspec/test unit - Model unit tests.
• Define feature scenario in cucumber • Start by implementing every step of feature scenario• For each functionality required BDD that with rspec• Repeat until functionality is complete
26
![Page 27: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/27.jpg)
Infosys Confidential © 2012
Hooks
• Hooks:• • Before - every scenario• • After - every scenario• • AfterStep - after every step
27
![Page 28: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/28.jpg)
Infosys Confidential © 2012
Backgrounds
• Steps that are invoked • Before and After every scenario
• Feature: browse books• Background: Logged in• Given I have logged in as “Aruna"• And the following models exist:• | manufacturer | carmodel? |• | Ford | yes |• | Honda| no |• Scenario: Display a car that already exists• Scenario: Display a car that is not yet in market
28
![Page 29: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/29.jpg)
Infosys Confidential © 2012
Configuration
• Command Line configuration for:
• Switches• Options
• Eg: • mycmd: --tags @wip features
• Usage:• cucumber –p mycmd
29
![Page 30: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/30.jpg)
Infosys Confidential © 2012
References / Bibliography
• The Rspec Book by David Chelimsky and others published by The Pragmatic Bookshelf
• http://www.infoq.com• Wikipedia
30
![Page 31: Infosys Confidential © 2012 © 2012. Infosys Limited. Strictly private and confidential. No part of this document should be reproduced or distributed without](https://reader035.vdocuments.us/reader035/viewer/2022062618/5513cb555503463a298b4e8a/html5/thumbnails/31.jpg)
Infosys Confidential © 2012