integration testing with behat drupal

12
Integration Testing with Behat Oscar Merida March 2016

Upload: oscar-merida

Post on 21-Jan-2017

292 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Integration Testing with Behat drupal

Integration Testing with Behat

Oscar MeridaMarch 2016

Page 2: Integration Testing with Behat drupal

Why Automated Testing

● Old school “Click around to see if anything broke”● Should want a process that is:

– Repeatable– Can be automated– Not Prone to Human Error

Page 3: Integration Testing with Behat drupal

Forms of Testing

● Unit Testing / TDD● Integration Tests● UI Testing● Performance or Load Testing

Page 4: Integration Testing with Behat drupal

Behat / Mink

● Behat is a Behavior Driven Developement framework to help communicate how an application should behave.

● Mink is an extension to allow website testing by simulating interacting with it through a browser– Goutte: makes request, parses content, no JS– Selenium: controls a real browser, more setup.

Page 5: Integration Testing with Behat drupal

Installation

● In your project root with Composer:composer require behat/behatcomposer require behat/minkcomposer require behat/mink-selection2-drivercomposer require behat/mink-selenium2-drivercomposer require behat/mink-extension

● Or in your composer.json file: "require": { "behat/behat": "^3.0", "behat/mink": "^1.7", "behat/mink-selenium2-driver": "^1.3", "behat/mink-extension": "^2.1" },

Page 6: Integration Testing with Behat drupal

Verify Installation

● Behat and it's dependencies will download to your 'vendor/' folder

● Can check that it works with:vendo/bin/behat -V

Page 7: Integration Testing with Behat drupal

Drupal Integration

● The Behat Drupal Exentions integrates Behat, Mink, and Drupal.

● Provides out-of-the-box tests that are Drupal aware.

● Install with:composer require drupal/drupal-extension

Page 8: Integration Testing with Behat drupal

Configuration

● Be default looks for a “behat.yml” file.● First part – configures contexts

default:

suites:

default:

contexts:

- Drupal\DrupalExtension\Context\DrupalContext

- Drupal\DrupalExtension\Context\MarkupContext

- Drupal\DrupalExtension\Context\MessageContext

- FeatureContext

Page 9: Integration Testing with Behat drupal

Configuring extensions

● Additional configuration for Selenium integration

extensions:

Behat\MinkExtension:

goutte: ~

javascript_session: selenium2

selenium2:

wd_host: http://local.dev:4444/wd/hub

base_url: http://local.dev

Page 10: Integration Testing with Behat drupal

Configuring DrupalExtension

● Tell it about your site's regions

Drupal\DrupalExtension:

blackbox: ~

region_map:

breadcrumb: '#breadcrumb'

branding: '#region-branding'

branding_second: '#region-branding-second'

content: '#region-content'

content_zone: '#zone-content'

Page 11: Integration Testing with Behat drupal

Writing a Feature

● A “Feature” is a set of tests in a plain text file● Use “vendor/bin/behat --init” to create a features

directory.● You can have more than one feature file:

– “blog.feature”– “members.feature”– “homepage.feature”

Page 12: Integration Testing with Behat drupal

Global Elements feature

● Checks that certain blocks are present

Feature: Global Elements

Scenario: Homepage Contact Us Link

Given I am on the homepage

Then I should see the link "Contact Us" in the "branding_second" region

Then I should see the "Search" button in the "branding_second" region

Then I should see the "div#block-system-main-menu" element in the "menu" region