Testing 1.2.3...
Column
The introduction of Behat 3, and the subsequent release of the Behat Drupal Extension 3, opened up several new features with regards to testing Drupal sites. The concept of test suites, combined with the fact that all contexts are now treated equally, means that a site can have different suites of tests that focus on specific areas of need.
Background
Behat is a PHP framework for implementing Behavior Driven Development (BDD). The aim is to use ubiquitous language to describe value for everybody involved, from the stake-holders to the developers. A quick example:
In order to encourage visitors to become more engaged in the forums
Visitors who choose to post a topic or comment
Will earn a 'Communicator' badge
This is a Behat feature, there need be no magic or structure to this. The goal is to simply and concisely describe a feature of the site that provides true value. In Behat, features are backed up with scenarios. Scenarios are written in Gherkin and are mapped directly to step-definitions which execute against a site, and determine if, indeed, a given scenario is working.
Continuing with the above example:
Scenario: A user posts a comment to an existing topic and earns the communicator badge
Given a user is viewing a forum topic "Getting started with Behat"
When they post a comment
They should immediately see the "Communicator" badge
Each of the Given
, When
, and Then
steps are mapped to code using either regex, or newly in Behat 3, Turnip syntax: