Hello, there!

Let's learn about Behat!

Who am I?

Peter Sieg

What are we doing here?

  1. High-level overview of Behat.
  2. Start using Behat in a real Drupal site!

Following along?


  • A functioning Drupal site
  • PHP 5.3.5+ with the curl, mbstring, and xml libraries installed
  • curl CLI command





What is Behat?

From the horse's mouth

"Behat is an open source Behavior Driven Development framework for PHP 5.3+. What’s behavior driven development, you ask? It’s a way to develop software through a constant communication with stakeholders in form of examples; examples of how this software should help them, and you, to achieve your goals."


In other words

Behat is a testing framework that uses plain language to test user behavior on your site.

Developing without tests

It could happen to you...

  • Poor understanding of a feature leads to inadequate development.
  • Features built with bugs baked-in.
  • Stakeholders keep reporting functional regressions.
  • Stakeholders have no confidence in you or your work.

Developing with tests

How can Behat help me?

  • Discover stakeholder goals and functional requirements.
  • Improve the quality of your application.
  • Increase the stability of your application.
  • Give stakeholders confidence.

How about an example?

Feature: Articles can be created and edited.
  In order to inform users
  As an administrator
  I need to create and edit articles on the site

  Scenario: An administrator can edit an article
    Given I am logged in as a user with the administrator role
    Then I should be able to edit an Article

  Scenario: An authenticated user can not edit an article
    Given I am logged in as a user with the authenticated role
    When I go to "/node/add/article"
    Then the response status code should be 403
A file that represents a unit of functionality and includes definition, scenarios, and steps to facilitate testing that functionality.
A collection of steps that recreate conditions and user behavior patterns.
Plain language patterns that magically set up preconditions, trigger events, or make assertions about your application.
A specific set of words used at the beginning of step patterns for readability and to group steps into preconditions, actions, and assertions.
Categorization for features and scenarios.
A class that provide new ways of interacting with your application. Primarily this means providing additional steps.
A class that alters or adds functionality to Behat. Often extensions provide new contexts or integrate with other technologies (like Drupal).


How do I get started?

Let's do it together. Right now!

Step 1: Install Behat

Much of this is lifted directly from the Drupal Extension documentation.

Step 2: Configure Behat

Much of this is lifted directly from the Drupal Extension documentation.

Step 3: Verify installation

Step 4: Write a test!

Step 5: Write more tests!

What if that's not enough?

Write custom steps


Other cool things we didn't have time for

  • Testing JavaScript interaction in the browser.
  • Using continuous integration services to automate behat tests.