Date post: | 15-Aug-2015 |
Category: |
Engineering |
Upload: | ravindra-singh |
View: | 251 times |
Download: | 3 times |
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
Setup tests
● Create a folder DCB15 where you want to store all test files
for specific projects.
● Create file behat.yml in DCB15
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
References
More info - http://behat-drupal-extension.readthedocs.org/
http://behat-drupal-extension.readthedocs.org/
https://github.com/silverstripe-labs/silverstripe-behat-
extension
http://behat.readthedocs.org/en/v2.5/guides/1.gherkin.
html#scenario-outlines
https://www.youtube.com/watch?v=9cYhnTojaHU
http://2015.midcamp.org/session-proposal/automated-testing-
drupal-behat
@ravindrasingh01
Thank You!
Ravindra Singh (@ravindrasingh01)
https://www.drupal.org/u/ravindrasingh