behat for writing tests in a stylized way

19
Writing tests in a stylized way @DrupalBangalore - Date 25 July 2015 www.srijan.net Ravindra Singh @ravindrasingh01

Upload: ravindra-singh

Post on 15-Aug-2015

250 views

Category:

Engineering


3 download

TRANSCRIPT

Writing tests in a stylized way

@DrupalBangalore - Date 25 July 2015 www.srijan.net

Ravindra Singh @ravindrasingh01

Scenario: Successfully authenticating with correct credentialsGiven there is a user “everzet” with password “123” And I am on the login pageWhen I fill in “username” with “everzet”And I fill in “password” with “123”And I press “login”Then I should see “Hello, everzet”

In order to get access to the shopping history As a frequent buyer I need to be able to authenticate

As a buyer I want to see the shopping history

Requirement:

Feature:

Dev Team

Client

Scenario: Successfully authenticating with correct credentialsGiven there is a user “everzet” with password “123” And I am on the login pageWhen I fill in “username” with “everzet”And I fill in “password” with “123”And I press “login”Then I should see “Hello, everzet”

In order to get access to the shopping history As a frequent buyer I need to be able to authenticate

As a buyer I want to see the shopping history

Requirement:

Feature:

Dev Team

Client

StoryBDD helps ensuring that development

team has understanding of business on the

same level that client does

Scenario: Successfully authenticating with correct credentialsGiven there is a user “everzet” with password “123” And I am on the login pageWhen I fill in “username” with “everzet”And I fill in “password” with “123”And I press “login”Then I should see “Hello, everzet”

In order to get access to the shopping history As a frequent buyer I need to be able to authenticate

As a buyer I want to see the shopping history

Requirement:

Feature:

Dev Team

Client

Agenda

● Introduction to Behat

● Behat Drupal Extension

● Behat Installation/Configuration

● Behat test execution from command line

● A real world example

● How to minimize regressing testing using Behat

What is Behat?

● Welcome to Behat! Behat is a tool that makes behavior

driven development(BDD) possible. With BDD, you write

human-readable stories that describe the behavior of your

application. These stories can then be auto-tested against

your application. And yes, it’s as cool as it sounds!

Drupal Extension

The Drupal Extension to Behat and Mink assists in the

performance of these common Drupal testing tasks:

● Set up test data with Drush or the Drupal API

● Define theme regions and test data appears within them

● Clear the cache, log out, and other useful steps

● Detect and discover steps provided by contributed

modules and themes

● Detail - https://www.drupal.org/project/drupalextension

Installation using Composer

1. Install Composer

2. Install the Drupal Extension in /opt/drupalextension

3. Create an alias to the behat binary in /usr/local/bin

4. Create your test folder

Installation using Composer

Installation using Composer

Installation using Composer

Setup tests

● Create a folder DCB15 where you want to store all test files

for specific projects.

● Create file behat.yml in DCB15

Dry Run● To ensure everything is set up appropriately, type:

behat -dl

WeAre

Ready

Real world example

Feature: H1 Validations In order to check H1 As visitor I need to validate headings are in H1 tag

Scenario: Test the ability to find a heading in a region Given I go to "http://d8localdev.me/" When I click "Create new account" Then I should see the heading "Create new account" in the "content" region

Regression Testing

Drupal API Driver

Drush Driver

More info - http://behat-drupal-extension.readthedocs.org/

@ravindrasingh01

Thank You!

Ravindra Singh (@ravindrasingh01)

https://www.drupal.org/u/ravindrasingh