2Contents BDD Installation Demo for Rspec Demo for Cucumber The Basic FeaturesCucumber vs. Rspec
3An elephant as seen by 6 blind people! A storyAn 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???
4Introduction 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 stakeholdersVision is to bring in consistency, accuracy and meaningBehavior Driven Development (BDD) claims “the words you use about something influence the way you think about that”.
5How it works?As <a ROLE> I need a <FEATURE> towards <BENEFIT>ExamplesAs an <ADMIN> I need <ACCESS TO FUNCTIONAL ADMIN PORTAL> to <MANAGE USERS>As the <IT MANAGER> I need <DETAILED REPORT> to <VALIDATE IT SPEND>
6Key stakeholders in a project Developer –Interested in coding than testingIf tester finds a defect or if time permits …… focus on defectsLet me code first is the general tendencyTester –Primary responsibility is to test and find defectsCustomer –Clarifications, approvals, sign offDifferent 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.
7Then……what is BDDIn the "Agile specifications, BDD and Testing eXchange" in November 2009 in London, Dan North 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.
8About them… RSpec created by Steven Baker in 2005. To explore new TDD frameworksEncourage focus on behavior…. Rspec2008, Aslak HellesøyTo explore new BDD frameworksRewrites RSpec’s Story Runner with a real grammar… Cucumber
17User stories Consider: User navigates to home page User enters details User successfully logs inUser unsuccessful in logging in
18DEMO: Multiple scenarios Website: adding more scenarios without tables
19Scenario outlines Let us define a single scenario outline Tables of input dataExpected output.
20Sample: Scenario outlines Scenario Outline: submit guessGiven the secret code is "<code>"When I guess "<guess>"Then the symbol should be "<symbol>"
21Sample: scenario Outlines Scenario Outline: submit detailsGiven 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 | | passed || ba-mn| | failed |
22Test doublesAn object that behaves as though it is the original objectEg: output
23Demo: Test DoubleUses test double but shows logical error
24“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
25A 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
26When Cucumber & WHEN Rspec Cucumber - integration/acceptance testingrspec/test unit - Model unit tests.Define feature scenario in cucumberStart by implementing every step of feature scenarioFor each functionality required BDD that with rspecRepeat until functionality is complete
27Hooks Hooks: • Before - every scenario • After - every scenario • AfterStep - after every step
28Backgrounds Steps that are invoked Before and After every scenario Feature: browse booksBackground: Logged inGiven I have logged in as “Aruna"And the following models exist:| manufacturer | carmodel? || Ford | yes || Honda| no |Scenario: Display a car that already existsScenario: Display a car that is not yet in market