Zend con 2016 bdd with behat for beginners

Adam Englander
Adam EnglanderDeveloper, speaker, author, IoT enthusiast and lover of all things community at ZettaFi
Zend con 2016   bdd with behat for beginners
Welcome to Las Vegas!
Session Breakdown
Preface (this)
Intro to BDD
Intro to Behat
Build some Tests
Why Are You Here?
What is your role in the development lifecycle?
What is your reason for attending this session?
What do you hope to get out of this session?
What is your experience level with PHP, Behat,
and BDD?
Pre-Run Checklist
Make sure you have:
PHP 5.6+ w/Composer
https://github.com/aenglander/bdd-with-behat-for-
beginners
Selenium Server and a browser with the Selenium
driver (Optional)
Gotchas
Missing one of these extensions:
curl
mbstring
openssl
No default timezone in PHP.ini
Zend con 2016   bdd with behat for beginners
What is BDD?
BDD is business driven, user focused, and test first.
It focuses on delivering business value as effectively
and efficiently as possible while maintaining
consistent quality throughout the entire application.
BDD is a methodology built around the principles of
lean development, extreme programming, test driven
development, and domain driven design.
What BDD Provides
Better understanding of the business requirement for
development and QA
Better understanding of existing features for the
business
Better communication via a ubiquitous language
Real insight into the business effect of a defect
What BDD Doesn’t Provide
The answer to all your problems
A replacement for unit testing
A replacement for manual testing
Super easy to implement everywhere right this second
A measure of code quality
Failed to Assert False is True
or
How I learned to love BDD
Zend con 2016   bdd with behat for beginners
Stay Focused
It is crucial to the success of BDD to focus on what
value a feature provides to the business.
Always understand the the role of the user and
their relationship to the feature.
Do not get distracted by the technical aspects of
the implementation.
Story BDD Hierarchy
Feature
Background (optional)
Scenario
Step Step
Scenario
Step Step
Writing Features
Applications are comprised of features
BDD discretely separates each feature into its
very own set of tests
Separated use cases into scenarios
Narrative
Feature narratives are written similarly to Agile/Scrum
stories and must answer these questions:
What is the business benefit?
Who is the beneficiary?
What is the action performed?
Background
A background should contain steps common to all, or
at least most, scenarios to prepare the application
environment for the scenarios.
Background steps should be tested elsewhere as part
of another feature.
Steps failing in the background steps will identify that
the failure is not related to the feature.
Scenario
A scenarios should contain a descriptive narrative
Scenarios work in a manner similar to unit tests by arranging
the environment necessary to begin the test, perform
actions, and then assert that the expected results have been
attained
Scenarios should not test multiple features. Do not perform
actions after assertions.
Scenario Outline
Scenario outlines use a common set of steps with
placeholders for data provided in a data table.
They are a replacement for multiple scenarios in which
data is the only differentiator and does not define the
feature. Adding sales tax would be an example of a
feature in which the data in the action and assertion
would be different.
Step
Steps do one of the following:
Arrange the environment
Perform an action
Assert a result of the previous actions
Steps should be reasonably reusable
Steps should be aggregated for simplification when
arranging the environment
Zend con 2016   bdd with behat for beginners
What is Behat?
Open source Behavior Driven Development
framework for PHP
Official PHP implementation of Cucumber
One of the easiest Cucumber implementations to
get up and running quickly
Good documentation: http://docs.behat.org
Installation
PHAR installation
Single global install
One version for feature contexts
Project Installation
Composer based install as dependency
Version and dependencies tied to project
Components
Command line executable – behat
Configuration file – behat.yml
Feature context(s)
Feature Files
Command Line Executable
Allows for initializing the environment
Running features
Features and scenarios filterable by tags
Chooses environment
Listing step definitions
Configuration File
Split up into profiles
(inherit from default)
Configures custom
autoloader path
Defines global tag filters
Defines output
formatters
Defines feature suites
Configures extensions
Feature Context
Defines steps
May extend other contexts
May access other contexts
May add hooks for pre/post tag, step, scenario,
feature, and suite execution.
Gherkin
Gherkin is a Domain Specific Language (DSL)
utilized to write Features in Behat. It uses key words
to identify the type of step:
Given – Arrange
When – Act
Then - Assert
Example Gherkin
Feature: Home Page
Scenario: Login Link
Given I am on the homepage
When I click " Login"
Then I will be on the "LaunchKey | Log in"
page
Step Backing Code
Method on a feature context
Contains doc block annotated (@) matchers
Support defined in context. Defaults to Turnip
Supports Turnip and regular expressions
Can contain examples doc block
Can contain descript in the doc block
Example Step
/**
* Opens homepage
* Example: Given I am on "/"
* Example: When I go to "/"
* Example: And I go to "/”
* @Given (I )am on :path
* @When (I )go to :path
*/
public function visitPath($path)
{
$this->browser->open($path);
}
Zend con 2016   bdd with behat for beginners
Create a Project
Composer “init”
Add requirements
Behat “init”
Add Contexts to Config
Verify Your Install
Run “vendor/bin/behat –h”
You should see the help text
Initialize Behat
Initialize the behat project via the Behat CLI
with the --init flag
Verify by running “vendor/bin/behat”
Add Mink to Config
• Add the extension to the default profile
• Set the base URL
• Add the drivers
Add Contexts to Config
• Add Mink context to get access to pre-built
browser steps
• Add project context to make custom steps
Verify Configuration
Run “vendor/bin/behat –dl”
You should see a LOT of steps
Run “vendor/bin/behat –di”
You should see additional information for the
steps
Lets Write A Feature Test
User Story:
In order to use the site
As a site visitor
I can access the website
Let’s Make Another
Requirement:
In order to be a user
As a visitor
I can register for a user account
What About Clean Up
Requirement:
E-Mail Address is the user identifier and must be
unique among all users
We’re going to have to clean up users in a hook
Steps Need to Be Intuitive
Checking for errors on registration submission
will require a custom step with some additional
logic
Add Other Requirements
E-Mail Address is the user identifier and must be
unique among all users
Name is required and captures the users name
Password is required and must utilize a verification
field to ensure correct password entry
Finish Up Labs/Examples
Server and Behat features found in GitHub:
https://github.com/aenglander/bdd-with-behat-for-
beginners
Master branch is Behat
Master is tagged to go step by step
Server branch is server
Selenium
Industry standard
Server with remote API
Direct integration with Behat/Mink via Selenium
Driver
Can be used headless with PhantomJS via
GhostDriver implementation
Using Selenium Server
Add config to bahat.yml and specify browser
Apply @javascript tag to scenarios or a feature
Start Selenium Standalone Server
Run tests
Selenium Grid
Allows for multiple simultaneous test runs, multiple
browser versions, and multiple operating systems
One Hub and Multiple Nodes
Uses same app as Standalone Server
Can be flakey and hard to manage
Sauce Labs/BrowserStack
Special Drivers for Sauce Labs and
BrowserStack
Not well documented but work very well
Allow for a “Grid” style environment without
managing the Grid
Configuring Mink Driver
Poorly documented
Easy to figure out the settings by looking at the
driver factories. See:
vendor/behat/mink-
extension/src/Behat/MinkExtension/ServiceContainer
/Driver
Best Practices
Feature files contain one Feature
Features should be more business than
technical focused
Best Practices (cont.)
Use the three A’s
Arrange – Background – Given
Act – When
Assert - Then
Best Practices (cont.)
Make steps visually verifiable. Feature files
should be able to serve as documentation
Clean up after yourself
Scenarios should be idempotent
Spend the time to do it the right way
1 of 52

Recommended

Php Dependency Management with Composer ZendCon 2016 by
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Clark Everetts
1K views75 slides
Composer - The missing package manager for PHP by
Composer - The missing package manager for PHPComposer - The missing package manager for PHP
Composer - The missing package manager for PHPTareq Hasan
17.6K views113 slides
PHP on Windows - What's New by
PHP on Windows - What's NewPHP on Windows - What's New
PHP on Windows - What's NewZendCon
2.4K views20 slides
PHP on IBM i Tutorial by
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i TutorialZendCon
6.6K views82 slides
2021.laravelconf.tw.slides1 by
2021.laravelconf.tw.slides12021.laravelconf.tw.slides1
2021.laravelconf.tw.slides1LiviaLiaoFontech
396 views65 slides
Becoming A Php Ninja by
Becoming A Php NinjaBecoming A Php Ninja
Becoming A Php NinjaMohammad Emran Hasan
4K views28 slides

More Related Content

What's hot

DB2 and PHP in Depth on IBM i by
DB2 and PHP in Depth on IBM iDB2 and PHP in Depth on IBM i
DB2 and PHP in Depth on IBM iAlan Seiden
2.4K views122 slides
Zend Core on IBM i - Security Considerations by
Zend Core on IBM i - Security ConsiderationsZend Core on IBM i - Security Considerations
Zend Core on IBM i - Security ConsiderationsZendCon
4.9K views48 slides
Best Practices in PHP Application Deployment by
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentShahar Evron
7.5K views29 slides
Killer Docker Workflows for Development by
Killer Docker Workflows for DevelopmentKiller Docker Workflows for Development
Killer Docker Workflows for DevelopmentChris Tankersley
159 views64 slides
Building and deploying PHP applications with Phing by
Building and deploying PHP applications with PhingBuilding and deploying PHP applications with Phing
Building and deploying PHP applications with PhingMichiel Rook
47.9K views60 slides
PHP Quality Assurance Workshop PHPBenelux by
PHP Quality Assurance Workshop PHPBeneluxPHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxNick Belhomme
6.4K views25 slides

What's hot(20)

DB2 and PHP in Depth on IBM i by Alan Seiden
DB2 and PHP in Depth on IBM iDB2 and PHP in Depth on IBM i
DB2 and PHP in Depth on IBM i
Alan Seiden2.4K views
Zend Core on IBM i - Security Considerations by ZendCon
Zend Core on IBM i - Security ConsiderationsZend Core on IBM i - Security Considerations
Zend Core on IBM i - Security Considerations
ZendCon4.9K views
Best Practices in PHP Application Deployment by Shahar Evron
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application Deployment
Shahar Evron7.5K views
Killer Docker Workflows for Development by Chris Tankersley
Killer Docker Workflows for DevelopmentKiller Docker Workflows for Development
Killer Docker Workflows for Development
Chris Tankersley159 views
Building and deploying PHP applications with Phing by Michiel Rook
Building and deploying PHP applications with PhingBuilding and deploying PHP applications with Phing
Building and deploying PHP applications with Phing
Michiel Rook47.9K views
PHP Quality Assurance Workshop PHPBenelux by Nick Belhomme
PHP Quality Assurance Workshop PHPBeneluxPHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBenelux
Nick Belhomme6.4K views
PHP and Platform Independance in the Cloud by ZendCon
PHP and Platform Independance in the CloudPHP and Platform Independance in the Cloud
PHP and Platform Independance in the Cloud
ZendCon1.3K views
PHP Toolkit from Zend and IBM: Open Source on IBM i by Alan Seiden
PHP Toolkit from Zend and IBM: Open Source on IBM iPHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM i
Alan Seiden40.5K views
Using PHP Functions! (Not those functions, Google Cloud Functions) by Chris Tankersley
Using PHP Functions! (Not those functions, Google Cloud Functions)Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)
Chris Tankersley177 views
Performance tips for Symfony2 & PHP by Max Romanovsky
Performance tips for Symfony2 & PHPPerformance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHP
Max Romanovsky1.6K views
HTML5 Real-Time and Connectivity by Peter Lubbers
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and Connectivity
Peter Lubbers11.3K views
Web Development with Python and Django by Michael Pirnat
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
Michael Pirnat188.7K views
Performance tuning with zend framework by Alan Seiden
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend framework
Alan Seiden7.7K views
Virtual Bolt Workshop - 6 May by Puppet
Virtual Bolt Workshop - 6 MayVirtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 May
Puppet220 views
Zend expressive workshop by Adam Culp
Zend expressive workshopZend expressive workshop
Zend expressive workshop
Adam Culp1.7K views
EuroPython 2011 - How to build complex web applications having fun? by Andrew Mleczko
EuroPython 2011 - How to build complex web applications having fun?EuroPython 2011 - How to build complex web applications having fun?
EuroPython 2011 - How to build complex web applications having fun?
Andrew Mleczko12.4K views

Similar to Zend con 2016 bdd with behat for beginners

PHPConf.asia 2016 - BDD with Behat for Beginners by
PHPConf.asia 2016 - BDD with Behat for BeginnersPHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for BeginnersAdam Englander
357 views51 slides
CucumberSeleniumWD by
CucumberSeleniumWDCucumberSeleniumWD
CucumberSeleniumWDVikas Sarin
275 views65 slides
Php[tek] 2016 - BDD with Behat for Beginners by
Php[tek] 2016 - BDD with Behat for BeginnersPhp[tek] 2016 - BDD with Behat for Beginners
Php[tek] 2016 - BDD with Behat for BeginnersAdam Englander
726 views71 slides
Behavior Driven Development by Example by
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by ExampleNalin Goonawardana
4.3K views50 slides
Cucumber_Training_ForQA by
Cucumber_Training_ForQACucumber_Training_ForQA
Cucumber_Training_ForQAMeenakshi Singhal
628 views43 slides

Similar to Zend con 2016 bdd with behat for beginners(20)

PHPConf.asia 2016 - BDD with Behat for Beginners by Adam Englander
PHPConf.asia 2016 - BDD with Behat for BeginnersPHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for Beginners
Adam Englander357 views
CucumberSeleniumWD by Vikas Sarin
CucumberSeleniumWDCucumberSeleniumWD
CucumberSeleniumWD
Vikas Sarin275 views
Php[tek] 2016 - BDD with Behat for Beginners by Adam Englander
Php[tek] 2016 - BDD with Behat for BeginnersPhp[tek] 2016 - BDD with Behat for Beginners
Php[tek] 2016 - BDD with Behat for Beginners
Adam Englander726 views
BDD Selenium for Agile Teams - User Stories by Sauce Labs
BDD Selenium for Agile Teams - User StoriesBDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User Stories
Sauce Labs1.5K views
BDD with Behat and Symfony2 by katalisha
BDD with Behat and Symfony2BDD with Behat and Symfony2
BDD with Behat and Symfony2
katalisha5.8K views
Behaviour Driven Development V 0.1 by willmation
Behaviour Driven Development V 0.1Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1
willmation223 views
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013 by Mack Hardy
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Mack Hardy8.1K views
Automated Acceptance Tests & Tool choice by toddbr
Automated Acceptance Tests & Tool choiceAutomated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choice
toddbr8K views
Slides from LAX & DEN usergroup meetings by 10n Software, LLC
Slides from LAX & DEN usergroup meetingsSlides from LAX & DEN usergroup meetings
Slides from LAX & DEN usergroup meetings
10n Software, LLC619 views
Introducing BDD and TDD with Cucumber by Knoldus Inc.
Introducing BDD and TDD with CucumberIntroducing BDD and TDD with Cucumber
Introducing BDD and TDD with Cucumber
Knoldus Inc.205 views
MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ... by Jitendra Bafna
MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ...MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ...
MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ...
Jitendra Bafna679 views
Joomla! Day Chicago 2011 Presentation - Steven Pignataro by Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Steven Pignataro428 views
[drupalday2017] - Behat per Drupal: test automatici e molto di più by DrupalDay
[drupalday2017] - Behat per Drupal: test automatici e molto di più[drupalday2017] - Behat per Drupal: test automatici e molto di più
[drupalday2017] - Behat per Drupal: test automatici e molto di più
DrupalDay257 views
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio by NCCOMMS
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual StudioSPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
NCCOMMS6K views
The "Holy Grail" of Dev/Ops by Erik Osterman
The "Holy Grail" of Dev/OpsThe "Holy Grail" of Dev/Ops
The "Holy Grail" of Dev/Ops
Erik Osterman516 views
TDD with BizTalk by Ben Carey
TDD with BizTalkTDD with BizTalk
TDD with BizTalk
Ben Carey968 views

More from Adam Englander

Making PHP Smarter - Dutch PHP 2023.pptx by
Making PHP Smarter - Dutch PHP 2023.pptxMaking PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxAdam Englander
39 views62 slides
Practical API Security - PyCon 2019 by
Practical API Security - PyCon 2019Practical API Security - PyCon 2019
Practical API Security - PyCon 2019Adam Englander
318 views84 slides
Threat Modeling for Dummies by
Threat Modeling for DummiesThreat Modeling for Dummies
Threat Modeling for DummiesAdam Englander
253 views56 slides
ZendCon 2018 - Practical API Security by
ZendCon 2018 - Practical API SecurityZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API SecurityAdam Englander
311 views77 slides
ZendCon 2018 - Cryptography in Depth by
ZendCon 2018 - Cryptography in DepthZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in DepthAdam Englander
244 views275 slides
Threat Modeling for Dummies - Cascadia PHP 2018 by
Threat Modeling for Dummies - Cascadia PHP 2018Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018Adam Englander
1.4K views58 slides

More from Adam Englander(20)

Making PHP Smarter - Dutch PHP 2023.pptx by Adam Englander
Making PHP Smarter - Dutch PHP 2023.pptxMaking PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptx
Adam Englander39 views
Practical API Security - PyCon 2019 by Adam Englander
Practical API Security - PyCon 2019Practical API Security - PyCon 2019
Practical API Security - PyCon 2019
Adam Englander318 views
ZendCon 2018 - Practical API Security by Adam Englander
ZendCon 2018 - Practical API SecurityZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API Security
Adam Englander311 views
ZendCon 2018 - Cryptography in Depth by Adam Englander
ZendCon 2018 - Cryptography in DepthZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in Depth
Adam Englander244 views
Threat Modeling for Dummies - Cascadia PHP 2018 by Adam Englander
Threat Modeling for Dummies - Cascadia PHP 2018Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018
Adam Englander1.4K views
Dutch PHP 2018 - Cryptography for Beginners by Adam Englander
Dutch PHP 2018 - Cryptography for BeginnersDutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for Beginners
Adam Englander268 views
php[tek] 2108 - Cryptography Advances in PHP 7.2 by Adam Englander
php[tek] 2108 - Cryptography Advances in PHP 7.2php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2
Adam Englander246 views
php[tek] 2018 - Biometrics, fantastic failure point of the future by Adam Englander
php[tek] 2018 - Biometrics, fantastic failure point of the futurephp[tek] 2018 - Biometrics, fantastic failure point of the future
php[tek] 2018 - Biometrics, fantastic failure point of the future
Adam Englander146 views
Biometrics: Sexy, Secure and... Stupid - RSAC 2018 by Adam Englander
Biometrics: Sexy, Secure and... Stupid - RSAC 2018Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Adam Englander170 views
Practical API Security - PyCon 2018 by Adam Englander
Practical API Security - PyCon 2018Practical API Security - PyCon 2018
Practical API Security - PyCon 2018
Adam Englander600 views
Practical API Security - Midwest PHP 2018 by Adam Englander
Practical API Security - Midwest PHP 2018Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018
Adam Englander270 views
Cryptography for Beginners - Midwest PHP 2018 by Adam Englander
Cryptography for Beginners - Midwest PHP 2018Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018
Adam Englander231 views
Cryptography for Beginners - Sunshine PHP 2018 by Adam Englander
Cryptography for Beginners - Sunshine PHP 2018Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018
Adam Englander405 views
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future by Adam Englander
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the FutureConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
Adam Englander171 views
Con Foo 2017 - Don't Loose Sleep - Secure Your REST by Adam Englander
Con Foo 2017 - Don't Loose Sleep - Secure Your RESTCon Foo 2017 - Don't Loose Sleep - Secure Your REST
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
Adam Englander234 views
ZendCon 2017 - Cryptography for Beginners by Adam Englander
ZendCon 2017 - Cryptography for BeginnersZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for Beginners
Adam Englander691 views
ZendCon 2017: The Red Team is Coming by Adam Englander
ZendCon 2017: The Red Team is ComingZendCon 2017: The Red Team is Coming
ZendCon 2017: The Red Team is Coming
Adam Englander327 views
ZendCon 2017 - Build a Bot Workshop - Async Primer by Adam Englander
ZendCon 2017 - Build a Bot Workshop - Async PrimerZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async Primer
Adam Englander333 views
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat by Adam Englander
Symfony Live San Franciso 2017 - BDD API Development with Symfony and BehatSymfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Adam Englander252 views

Recently uploaded

.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... by
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...Marc Müller
35 views62 slides
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut... by
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...HCLSoftware
6 views2 slides
El Arte de lo Possible by
El Arte de lo PossibleEl Arte de lo Possible
El Arte de lo PossibleNeo4j
34 views35 slides
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Marc Müller
31 views83 slides
Cycleops - Automate deployments on top of bare metal.pptx by
Cycleops - Automate deployments on top of bare metal.pptxCycleops - Automate deployments on top of bare metal.pptx
Cycleops - Automate deployments on top of bare metal.pptxThanassis Parathyras
30 views12 slides
SAP FOR TYRE INDUSTRY.pdf by
SAP FOR TYRE INDUSTRY.pdfSAP FOR TYRE INDUSTRY.pdf
SAP FOR TYRE INDUSTRY.pdfVirendra Rai, PMP
19 views3 slides

Recently uploaded(20)

.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... by Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller35 views
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut... by HCLSoftware
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...
HCLSoftware6 views
El Arte de lo Possible by Neo4j
El Arte de lo PossibleEl Arte de lo Possible
El Arte de lo Possible
Neo4j34 views
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller31 views
Cycleops - Automate deployments on top of bare metal.pptx by Thanassis Parathyras
Cycleops - Automate deployments on top of bare metal.pptxCycleops - Automate deployments on top of bare metal.pptx
Cycleops - Automate deployments on top of bare metal.pptx
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... by Deltares
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
Deltares7 views
DSD-INT 2023 Modelling litter in the Yarra and Maribyrnong Rivers (Australia)... by Deltares
DSD-INT 2023 Modelling litter in the Yarra and Maribyrnong Rivers (Australia)...DSD-INT 2023 Modelling litter in the Yarra and Maribyrnong Rivers (Australia)...
DSD-INT 2023 Modelling litter in the Yarra and Maribyrnong Rivers (Australia)...
Deltares9 views
DSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - Parker by Deltares
DSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - ParkerDSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - Parker
DSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - Parker
Deltares8 views
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ... by marksimpsongw
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...
marksimpsongw74 views
Advanced API Mocking Techniques by Dimpy Adhikary
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking Techniques
Dimpy Adhikary18 views
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge... by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
Deltares16 views
Applying Platform Engineering Thinking to Observability.pdf by Natan Yellin
Applying Platform Engineering Thinking to Observability.pdfApplying Platform Engineering Thinking to Observability.pdf
Applying Platform Engineering Thinking to Observability.pdf
Natan Yellin12 views
How to Make the Most of Regression and Unit Testing.pdf by Abhay Kumar
How to Make the Most of Regression and Unit Testing.pdfHow to Make the Most of Regression and Unit Testing.pdf
How to Make the Most of Regression and Unit Testing.pdf
Abhay Kumar10 views
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... by Deltares
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
Deltares9 views
What Can Employee Monitoring Software Do?​ by wAnywhere
What Can Employee Monitoring Software Do?​What Can Employee Monitoring Software Do?​
What Can Employee Monitoring Software Do?​
wAnywhere18 views
Software evolution understanding: Automatic extraction of software identifier... by Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida by Deltares
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - PridaDSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida
Deltares17 views

Zend con 2016 bdd with behat for beginners

  • 2. Welcome to Las Vegas!
  • 3. Session Breakdown Preface (this) Intro to BDD Intro to Behat Build some Tests
  • 4. Why Are You Here? What is your role in the development lifecycle? What is your reason for attending this session? What do you hope to get out of this session? What is your experience level with PHP, Behat, and BDD?
  • 5. Pre-Run Checklist Make sure you have: PHP 5.6+ w/Composer https://github.com/aenglander/bdd-with-behat-for- beginners Selenium Server and a browser with the Selenium driver (Optional)
  • 6. Gotchas Missing one of these extensions: curl mbstring openssl No default timezone in PHP.ini
  • 8. What is BDD? BDD is business driven, user focused, and test first. It focuses on delivering business value as effectively and efficiently as possible while maintaining consistent quality throughout the entire application. BDD is a methodology built around the principles of lean development, extreme programming, test driven development, and domain driven design.
  • 9. What BDD Provides Better understanding of the business requirement for development and QA Better understanding of existing features for the business Better communication via a ubiquitous language Real insight into the business effect of a defect
  • 10. What BDD Doesn’t Provide The answer to all your problems A replacement for unit testing A replacement for manual testing Super easy to implement everywhere right this second A measure of code quality
  • 11. Failed to Assert False is True or How I learned to love BDD
  • 13. Stay Focused It is crucial to the success of BDD to focus on what value a feature provides to the business. Always understand the the role of the user and their relationship to the feature. Do not get distracted by the technical aspects of the implementation.
  • 14. Story BDD Hierarchy Feature Background (optional) Scenario Step Step Scenario Step Step
  • 15. Writing Features Applications are comprised of features BDD discretely separates each feature into its very own set of tests Separated use cases into scenarios
  • 16. Narrative Feature narratives are written similarly to Agile/Scrum stories and must answer these questions: What is the business benefit? Who is the beneficiary? What is the action performed?
  • 17. Background A background should contain steps common to all, or at least most, scenarios to prepare the application environment for the scenarios. Background steps should be tested elsewhere as part of another feature. Steps failing in the background steps will identify that the failure is not related to the feature.
  • 18. Scenario A scenarios should contain a descriptive narrative Scenarios work in a manner similar to unit tests by arranging the environment necessary to begin the test, perform actions, and then assert that the expected results have been attained Scenarios should not test multiple features. Do not perform actions after assertions.
  • 19. Scenario Outline Scenario outlines use a common set of steps with placeholders for data provided in a data table. They are a replacement for multiple scenarios in which data is the only differentiator and does not define the feature. Adding sales tax would be an example of a feature in which the data in the action and assertion would be different.
  • 20. Step Steps do one of the following: Arrange the environment Perform an action Assert a result of the previous actions Steps should be reasonably reusable Steps should be aggregated for simplification when arranging the environment
  • 22. What is Behat? Open source Behavior Driven Development framework for PHP Official PHP implementation of Cucumber One of the easiest Cucumber implementations to get up and running quickly Good documentation: http://docs.behat.org
  • 23. Installation PHAR installation Single global install One version for feature contexts Project Installation Composer based install as dependency Version and dependencies tied to project
  • 24. Components Command line executable – behat Configuration file – behat.yml Feature context(s) Feature Files
  • 25. Command Line Executable Allows for initializing the environment Running features Features and scenarios filterable by tags Chooses environment Listing step definitions
  • 26. Configuration File Split up into profiles (inherit from default) Configures custom autoloader path Defines global tag filters Defines output formatters Defines feature suites Configures extensions
  • 27. Feature Context Defines steps May extend other contexts May access other contexts May add hooks for pre/post tag, step, scenario, feature, and suite execution.
  • 28. Gherkin Gherkin is a Domain Specific Language (DSL) utilized to write Features in Behat. It uses key words to identify the type of step: Given – Arrange When – Act Then - Assert
  • 29. Example Gherkin Feature: Home Page Scenario: Login Link Given I am on the homepage When I click " Login" Then I will be on the "LaunchKey | Log in" page
  • 30. Step Backing Code Method on a feature context Contains doc block annotated (@) matchers Support defined in context. Defaults to Turnip Supports Turnip and regular expressions Can contain examples doc block Can contain descript in the doc block
  • 31. Example Step /** * Opens homepage * Example: Given I am on "/" * Example: When I go to "/" * Example: And I go to "/” * @Given (I )am on :path * @When (I )go to :path */ public function visitPath($path) { $this->browser->open($path); }
  • 33. Create a Project Composer “init” Add requirements Behat “init” Add Contexts to Config
  • 34. Verify Your Install Run “vendor/bin/behat –h” You should see the help text
  • 35. Initialize Behat Initialize the behat project via the Behat CLI with the --init flag Verify by running “vendor/bin/behat”
  • 36. Add Mink to Config • Add the extension to the default profile • Set the base URL • Add the drivers
  • 37. Add Contexts to Config • Add Mink context to get access to pre-built browser steps • Add project context to make custom steps
  • 38. Verify Configuration Run “vendor/bin/behat –dl” You should see a LOT of steps Run “vendor/bin/behat –di” You should see additional information for the steps
  • 39. Lets Write A Feature Test User Story: In order to use the site As a site visitor I can access the website
  • 40. Let’s Make Another Requirement: In order to be a user As a visitor I can register for a user account
  • 41. What About Clean Up Requirement: E-Mail Address is the user identifier and must be unique among all users We’re going to have to clean up users in a hook
  • 42. Steps Need to Be Intuitive Checking for errors on registration submission will require a custom step with some additional logic
  • 43. Add Other Requirements E-Mail Address is the user identifier and must be unique among all users Name is required and captures the users name Password is required and must utilize a verification field to ensure correct password entry
  • 44. Finish Up Labs/Examples Server and Behat features found in GitHub: https://github.com/aenglander/bdd-with-behat-for- beginners Master branch is Behat Master is tagged to go step by step Server branch is server
  • 45. Selenium Industry standard Server with remote API Direct integration with Behat/Mink via Selenium Driver Can be used headless with PhantomJS via GhostDriver implementation
  • 46. Using Selenium Server Add config to bahat.yml and specify browser Apply @javascript tag to scenarios or a feature Start Selenium Standalone Server Run tests
  • 47. Selenium Grid Allows for multiple simultaneous test runs, multiple browser versions, and multiple operating systems One Hub and Multiple Nodes Uses same app as Standalone Server Can be flakey and hard to manage
  • 48. Sauce Labs/BrowserStack Special Drivers for Sauce Labs and BrowserStack Not well documented but work very well Allow for a “Grid” style environment without managing the Grid
  • 49. Configuring Mink Driver Poorly documented Easy to figure out the settings by looking at the driver factories. See: vendor/behat/mink- extension/src/Behat/MinkExtension/ServiceContainer /Driver
  • 50. Best Practices Feature files contain one Feature Features should be more business than technical focused
  • 51. Best Practices (cont.) Use the three A’s Arrange – Background – Given Act – When Assert - Then
  • 52. Best Practices (cont.) Make steps visually verifiable. Feature files should be able to serve as documentation Clean up after yourself Scenarios should be idempotent Spend the time to do it the right way

Editor's Notes

  1. Extensions are usually pre-enabled by default with Linux or Mac package managers. Windows users need to uncomment the line n the php.ini. Search for “date.timezone”. Set it to whatever you like. If you are not sure you can use “UTC”.
  2. The direct correlation between the SOAP box and BDD is the reason BDD is becoming more and more popular.
  3. I never meant to learn BDD. I was just looking for a tool to help me stop breaking a critical legacy business application every time we released a new feature. We had built entire integration testing platforms but they would not give me or the business what we needed to identify defects and were constantly giving false positives and negatives to the brittle nature of the tests. The first step was using feature based testing with Cucumber and then Behat when it became available. Embracing BDD, like everything else in my career, was a process of enlightenment. It took time and required pain to drive growth.
  4. composer init composer require --dev behat/behat behat/mink-extension behat/mink-goutte-driver behat/mink-selenium2-driver vendor/bin/behat --init vendor/bin/behat -h
  5. vendor/bin/behat --init vendor/bin/behat
  6. default: extensions: Behat\MinkExtension: base_url: http://adam-bdd-with-behat.ngrok.io goutte: ~ selenium2: ~
  7. default: suites: default: contexts: - Behat\MinkExtension\Context\MinkContext - FeatureContext
  8. Vendor/bin/behat -dl
  9. Feature: A visitor can access the homepage In order to use the site As a site visitor I can access the website Scenario: Homepage loads When I go to the homepage Then I should see "Your Application's Landing Page. "
  10. Feature: User Registration In order to be a user As a visitor I can register for a user account Background: Given I am on "/register" Scenario: Proper fields register the user When I fill in the following: | Name | Adam | | E-Mail Address | test.email@launchkey.com | | Password | Password1 | | Confirm Password | Password1 | And I press "Register" Then I should be on the homepage And the response should contain "Logout"
  11. use Behat\Behat\Hook\Scope\BeforeScenarioScope; /** * @BeforeScenario */ public function cleanupUsers(BeforeScenarioScope $scope) { $this->mink = $scope->getEnvironment()->getContext('Behat\MinkExtension\Context\MinkContext'); $this->mink->visit(‘/delete-test-users’); }
  12. /** * @Then the :field field should have an error */ public function theFieldHasAnError($field) { $has = $this->mink->getSession() ->getPage() ->findField($field) ->getParent() ->has('css', 'span.help-block'); if ( ! $has) { throw new \Exception("Field \"{$field}\" has no error"); } }
  13. Behat\MinkExtension: browser_name: chrome goutte: ~ selenium2: ~