Behavior Driven Development - RBCS, IncBehavior Driven Development Using Tests to Define, Refine,...
Transcript of Behavior Driven Development - RBCS, IncBehavior Driven Development Using Tests to Define, Refine,...
Behavior Driven Development Using Tests to Define, Refine, and Verify Behavior
Behavior Driven Development Using Tests to Define, Refine, and Verify Behavior
Introductions, Objectives,
and Overview
Time Tested. Testing Improved
Exercises
In many of the exercises, you are working as a tester on the Omninet project
Omninet is a project to deploy a network of public access Internet kiosks in places like malls, theaters, and other public places
On this realistic project, you will have a chance to apply many of the techniques we discuss
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 3
Behavior Driven Development Using Tests to Define, Refine, and Verify Behavior
BDD, Cucumber, and Gherkins
Time Tested. Testing Improved
Behavior Driven Development
BDD does not focus on structure of system being developed
BDD focuses on behavioral aspects of the user and how the system helps the user
Gherkin is widely used in the Behavior Driven Development community to describe systems and automate tests
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 5
Time Tested. Testing Improved
Behavior Driven Development
Describing behavior
Given
• Something true
• A precondition
When
• Event
• Trigger
Then
• Expected outcome
• Ending state
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 6
Time Tested. Testing Improved
Behavior Driven Development
Example description with Given/When/Then syntax: Given I have $100 in checking
And I have $20 in savings
When I transfer $15 from checking
to savings
Then I should have $85 in
checking
And I should have $35 in savings
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 7
Time Tested. Testing Improved
Automating Story Tests with Cucumber
Cucumber is an open source tool used to automate story tests.
Cucumber uses “Gherkin”—a simple business-oriented, domain-specific, human-readable language—to let you describe system behavior and acceptance tests.
Cucumber user acceptance tests can be written by non-programmers.
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 8
Time Tested. Testing Improved
Automating Story Tests with Cucumber
Ref: http://wiki.github.com/aslakhellesoy/cucumber/gherkin
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 9
Time Tested. Testing Improved
Automating Story Tests with Cucumber
Ref: http://dev.camptocamp.com/files/operpScenario/result.html
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 10
Time Tested. Testing Improved
Automating Story Tests with Cucumber
Cucumber basics
Feature file contains user story
Feature file may contain many scenarios
Each scenario has a Given, When, and Then section
Each section has one or more steps
As new “features” are added, developers will need to incrementally add “step” definitions
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 11
Time Tested. Testing Improved
Cucumber Diagram
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 12
Time Tested. Testing Improved
Cucumber Testing Stack
Project Features Scenarios
Steps Step
Definitions Support
Code
Automation Library
Your System
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 13
Time Tested. Testing Improved
Exercise: Make a Gherkin
Consider section 3.1.2 of the Omninet Marketing Requirements Document (which you should already have read)
In small groups, evaluate this user story for section 3.1.2
As an Omninet customer,
I want to pay with a credit card,
So that I can browse the Internet
Define a Gherkin for this user story
Page 14 Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018
Time Tested. Testing Improved
Debrief
Each team presents its Gherkin to the other teams
Teams can ask question and make comments
Page 15 Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018
Behavior Driven Development Using Tests to Define, Refine, and Verify Behavior
Building Gherkin Scripts
Time Tested. Testing Improved
Gherkin Script Construction
Gherkin scripts reside in a feature file
A feature file relates to a single story
A feature file contains
statement of the story
collection of tests for the story
Tests in the feature file are called scenarios
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 17
Time Tested. Testing Improved
Gherkin Script Construction
Feature File
Story Scenarios
Scenario
Given
When
Then
Scenario
Given
When
Then
…
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 18
Time Tested. Testing Improved
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 19
Time Tested. Testing Improved
Gherkin Script Construction
Feature File
Simple unformatted text file
Parsed by Cucumber
Can be created with any text editor
Tools are available to edit Feature Files
• Tg – Tidy Gherkin
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 20
Time Tested. Testing Improved
Gherkin Script Construction
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 21
Time Tested. Testing Improved
Gherkin Script Construction
Feature File Keywords
Feature
• Name of the feature
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 22
Time Tested. Testing Improved
Gherkin Script Construction
Feature File Keywords
Scenario
• Name of the scenario
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 23
Time Tested. Testing Improved
Gherkin Script Construction
Feature File Keywords
Given
• Preconditions of a scenario
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 24
Time Tested. Testing Improved
Gherkin Script Construction
Feature File Keywords
When
• Conditions that trigger outcome of scenario
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 25
Time Tested. Testing Improved
Gherkin Script Construction
Feature File Keywords
Then
• Outcome of scenario
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 26
Time Tested. Testing Improved
Gherkin Script Construction
Feature File Keywords
And
• Conjunction in Given, When, or Then
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 27
Time Tested. Testing Improved
Gherkin Script Construction
Feature File Keywords
But
• Conjunction in Given, When, or Then
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 28
Time Tested. Testing Improved
Gherkin Script Construction
Feature File Keywords
Commentary
• Non-executable explanatory notations
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 29
Time Tested. Testing Improved
Gherkin Script Construction
Feature File Keywords
Background
• Steps that prefix each scenario
Behavior Driven Development www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 30
Time Tested. Testing Improved
Gherkin Script Construction
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 31
Time Tested. Testing Improved
Gherkin Script Construction
Feature File Constructs
Data table
• Data tables are a shorthand to provide several pieces of data in one step definition in any part of the Given, When, or Then Section
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 32
Time Tested. Testing Improved
Gherkin Script Construction
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 33
Time Tested. Testing Improved
Gherkin Script Construction
Feature File Constructs Scenario Outline
• Used when the same scenario is repeated several times with different data
• Parameterized scenarios
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 34
Time Tested. Testing Improved
Exercise: Make a Gherkin
Consider section 3.1.2 of the Omninet Marketing Requirements Document (which you should already have read)
In small groups, evaluate this user story for section 3.1.2
As an Omninet customer,
I want to pay with a credit card,
So that I can browse the Internet
Define up to three scenarios with associated Gherkins for this user story
Page 35 Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018
Time Tested. Testing Improved
Debrief
Each team presents its scenarios and Gherkins to the other teams
Teams can ask question and make comments
Page 36 Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018
Time Tested. Testing Improved
For over 20 years, RBCS has delivered consulting, training, and expert services to clients, helping them with software and hardware testing. Employing the industry’s most experienced and recognized consultants, RBCS advises its clients, trains their employees, conducts product testing, builds and improves testing groups, and hires testing staff for hundreds of clients worldwide. Ranging from Fortune 20 companies to start-ups, RBCS clients save time and money through improved product development, decreased tech support calls, improved corporate reputation and more. To learn more about RBCS, visit www.rbcs-us.com.
Address: RBCS, Inc. 31520 Beck Road
Bulverde, TX 78163-3911 USA Phone: +1 (830) 438-4830 E-mail: [email protected] Web: www.rbcs-us.com
Twitter: @RBCS, @MisterSDET, @LaikaTestDog
Facebook: @TestingImprovedbyRBCS LinkedIn: https://www.linkedin.com/in/rex-black YouTube: https://www.youtube.com/user/RBCSINC
…Contact RBCS
Behavior Driven Development
www.rbcs-us.com
Copyright (c) RBCS 2015-2018 Page 37