Solutions Architect at VML
Drupal developer since 2005
Kansas City Drupal Users Group
A communication and collaboration framework for developers, QA and non-technical or business participants in a software project
-- Wikipedia
Developing an application (as opposed to a unit of code) by:
Gherkin is a declarative, business readable, domain specific language created especially for behavior descriptions.
homepage.feature
Feature: Home Page
Tests the home page
Scenario: View home page
Given I am on "/"
Then I should see "Welcome to behat"
Using Behat as a standalone tool
Behat Runner Drupal module
Run:
mkdir drupalcorn_behat
composer.json
{
"require": {
"drupal/drupal-extension": "*"
},
"config": {
"bin-dir": "bin/"
}
}
Run:
composer install
drupalcorn_behat
├── behat.yml
├── bin
├── composer.json
├── composer.lock
└── vendor
behat.yml
default:
paths:
features: 'features'
extensions:
Behat\MinkExtension\Extension:
goutte: ~
selenium2: ~
base_url: http://behat/
Drupal\DrupalExtension\Extension:
blackbox: ~
Run:
mkdir features
features/homepage.features
Feature: Home Page
Tests the home page
Scenario: View home page
Given I am on "/"
Then I should see "Welcome to behat"
Run:
./bin/behat
YOU HAVE TO USE DRUSH!
Edit settings.php and set $base_url
drush en -y behatrunner
drush brm
drush bls
drush brun
New module just for testing - Behat Drupalcorn
behat_drupalcorn.info
name = Behat Drupalcorn
description = Sample module for Drupalcorn Behat talk
core = 7.x
dependencies[] = behatrunner
behat_drupalcorn.module
<?php
/**
* Implements hook_behat_info()
*/
function behat_drupalcorn_behat_info() {
$info = array(
'paths' => array(
'features' => 'features',
),
);
return $info;
}
features/homepage.feauture
Feature: Home Page
Tests the home page
Scenario: View home page
Given I am on "/"
Then I should see "Welcome to behat"
Setup - Blog feature
behat_talk_blog.behat_tests.inc:
<?php
/**
* Implements hook_behat_info()
*/
function behat_talk_blog_behat_info() {
$info = array(
'paths' => array(
'features' => 'features',
),
);
return $info;
}
Add this line to the end of behat_talk_blog.module:
include_once 'behat_talk_blog.behat_tests.inc';
features/blog.feature:
Feature: Blog
Tests the blog feature
Scenario: View blog page
Given I am on the homepage
When I click "Blog"
Then I should see "The Really Cool Blog"
Assumes no privileged access to the site
Server can be local or remote
Region Maps
Check for Drupal errors or messages
Allows tests to be run as logged in users with specific roles
Server can be local or remote
Allows tests to be run as logged in users with specific roles
Lets you create nodes, vocabularies, and terms in the test specs
Fastest of the three drivers
Must be run locally
@api
Scenario: Create blog post
Given "blog_post" nodes:
| title | body |
| First Post | Sample body content |
When I go to "blog"
Then I should see "First Post"
The drush and api drivers require the "@api" tag so the system knows to bootstrap Drupal
sites/default/files/behatrunner/behat.xml
default:
extensions:
Behat\MinkExtension\Extension:
goutte: null
default_session: goutte
javascript_session: selenium2
selenium2:
wd_host: 'http://127.0.0.1:4444/wd/hub'
base_url: 'http://behat'
Drupal\DrupalExtension\Extension:
blackbox: null
drush:
alias: '@self'
api_driver: drupal
drupal:
drupal_root: /var/www/behat
region_map:
footer: #footer
Lets you write reusable step definitions for your modules
Install Behat standalone (with the Drupal Extension) or the Behat Runner module
Use the Goutte Mink driver
Create a single feature file with the simplest scenario you can think of
Any time you get a bug report write the test first then fix it
Integrate the test with Jenkins/whatever to run when code is checked in
Make test reviews part of your code/build reviews
When bugs are maked as fixed ensure they have a test before they're closed
Reward/shame team member create (or fail to create) tests
Behat/Mink - http://behat.org
Gherkin - http://docs.behat.org/guides/1.gherkin.html
Drupal Extension - https://www.drupal.org/project/drupalextension
Drupal Extension Docs - http://dspeak.com/drupalextension
Behat Runner - https://www.drupal.org/project/behatrunner
My Github - https://github.com/karlkedrovsky
Email - karl@kedrovsky.com or kkedrovsky@vml.com
Twitter - @karlkedrovsky
Drupal.org - https://www.drupal.org/u/karlkedrovsky