Top Banner
Writing tests in a stylized way @DrupalBangalore - Date 25 July 2015 www.srijan.net Ravindra Singh @ravindrasingh01
19
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Behat for writing tests in a stylized way

Writing tests in a stylized way

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

Ravindra Singh @ravindrasingh01

Page 2: Behat for writing tests in a stylized way

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

Page 3: Behat for writing tests in a stylized way

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

Page 4: Behat for writing tests in a stylized way

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

Page 5: Behat for writing tests in a stylized way

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

Page 6: Behat for writing tests in a stylized way

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!

Page 7: Behat for writing tests in a stylized way

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

Page 8: Behat for writing tests in a stylized way

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

Page 9: Behat for writing tests in a stylized way

Installation using Composer

Page 10: Behat for writing tests in a stylized way

Installation using Composer

Page 11: Behat for writing tests in a stylized way

Installation using Composer

Page 12: Behat for writing tests in a stylized way

Setup tests

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

for specific projects.

● Create file behat.yml in DCB15

Page 13: Behat for writing tests in a stylized way

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

behat -dl

Page 14: Behat for writing tests in a stylized way

WeAre

Ready

Page 15: Behat for writing tests in a stylized way

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

Page 16: Behat for writing tests in a stylized way

Regression Testing

Page 17: Behat for writing tests in a stylized way

Drupal API Driver

Drush Driver

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

Page 19: Behat for writing tests in a stylized way

@ravindrasingh01

Thank You!

Ravindra Singh (@ravindrasingh01)

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