G2CROWD NAMES PANTHEON #1 IN WEBOPS See why real customers prefer our platform Learn More

Behat For Web Developers

An Introduction to Testing With Behat

A few weeks ago I gave a talk about testing business critical features with Behat at Midwest PHP. That talk came after working with Behat for over a year and consulting with our agency partners about automated testing.

I've found that a lot of web developers find Behat hard to get started with. So, I want to take what I've learned and dispel that myth by creating a quickstart guide for using Behat to assist with website testing.

Move fast and break things presentation slide

The Layers of Behat

Behat

Behat is a PHP framework for automated testing. It was built with communication as a focus to facilitate Behavior Driven Development (BDD). But, you don't need to adopt BDD to use Behat. This background is important, however, as it explains why Behat tests are written in Gherkin, a human-readable language. If you want to know more about Gherkin, the Cucumber Gherkin reference is a great doc.

When I first found the Behat documentation, I came across the quick intro from version 2.5. It shows an example of testing the ls command for Unix. This is great for understanding Gherkin, but as a web developer, wasn't something I could use to help test sites I maintain.

Mink

The ls example I found also helped me understand that Behat is a broad tool - allowing you to test just about anything you can do with PHP. So, how do we add a web focus?

That is where Mink comes in. Mink is an open source browser controller written in PHP that can be used with Behat. The best part? It comes with a ton of steps we can use for testing web applications out of the box.

Zero To Testing In 10 Minutes

To make it easy for anyone to learn Behat, I’ve written a guide, published in the Pantheon Documentation site to make sure the technical details are kept evergreen. Take a look when you’re ready to get started.

Frameworks to Match

If you find you are repeating the same things over and over, such as logging into WordPress or Drupal, try out some framework extensions. Each one adds additional steps, specific to their corresponding framework. Here are a few of my favorites.

Take Behat Into Your Own Hands

Hopefully, you were able to see how easy it is to get up and running with Behat. One of the reasons I like Behat is the extensive community and ecosystem. There are lots of great docs, guides, and blog posts out there. I encourage you to explore Behat in more depth and use it to automate testing for all your projects.


 

You may also like:

Topics Agencies, Agency Partners, Development, Drupal, Guides and Tutorials, Testing & Optimization, Website Technology, WordPress

Let’s get in touch

855-927-9387