SlideShare a Scribd company logo
Front-end Automated Testing
#drupal-fat
Ruben Teijeiro
I don't know
what I like
more: Drupal
or Beer

@rteijeiro
Based on a true history...
Web Development
In collaboration with
Developers
I'm ready for
website
development!
Drupal8 Front-end Automated Testing
DevOps
Almost finished
setting up your
server. Just one
minute...
WTF!!
Designers

Just redesigned
the website. Now
it's shinny, edgy
and it pops!!
So,
what?
Users
In-place Content Authoring
Holy
shit!!
Clients
Just something
And kitten
like Facebook!
pics. Everyone
We need it
loves kittens!
yesterday...

Better in
Comic Sans
Should work
also in IE7
OMG!!
Browsers
Drupal8 Front-end Automated Testing
Result
Front-end
I said: “{float: left;}” !!
Solution
Refactoring
Fixed

Fixed

Fixed

Fixed
Fixed

Fixed

Fixed
Oh
man!
DEMO
Drupal8 Front-end Automated Testing
BONUS!
And now I will
show you how it
looks like in
Internet Explorer...
Now
what?
FAT
Front-end Automated Testing
Because people like code that works
Continuous Integration
Push Button

Receive Bacon
Unit Test
Take one tablet every “git push”
·
·
·
·
·
·

Automated
Repeteable
Easy to understand
Incremental
Easy to run
Fast

Unit Test
Testing Tools

BA-K-47
Drupal 8 Modules
Drupal Modules

· TestSwarm
https://drupal.org/project/testswarm

· FAT
https://drupal.org/project/fat
Testing Frameworks
· QUnit
· CasperJS
· PhantomJS
· Jasmine

Testing Frameworks
TestSwarm module

QUnit Tests

FAT module
Bacon Module
Drupal8 Front-end Automated Testing
bacon.module
/**
* Implements hook_testswarm_tests().
*/
function bacon_testswarm_tests() {
'bacon_test' => array(
'module' => 'bacon',
'description' => 'Testing bacon.',
'js' => array(
$path . '/tests/bacon.tests.js' => array(),
),
'dependencies' => array(
array('testswarm', 'jquery.simulate'),
),
'path' => 'admin/bacon/test',
'permissions' => array('test bacon')
),
}
tests/bacon.tests.js
/*global Drupal: true, jQuery: true, QUnit:true*/
(function ($, Drupal, window, document, undefined) {
"use strict";
Drupal.tests.bacon = {
getInfo: function() {
return {
name: 'Bacon test',
description: 'Testing bacon.',
group: 'Bacon'
};
},
tests: function() {
[Insert your QUnit tests here]
},
};
})(jQuery, Drupal, this, this.document);
Setup
tests/bacon.tests.js
Drupal.tests.bacon = {
getInfo: function() {
return {
name: 'Bacon test',
description: 'Testing bacon.',
group: 'Bacon'
};
},
setup: function() {
[Insert your setup code here]
},
teardown: function() {
[Insert your teardown code here]
},
tests: function() {
[Insert your QUnit tests here]
},
};
QUnit
Assert
Assert

ok(state, message)
Passes if the first argument is truthy.

var bbq_ready = true;
QUnit.ok(bbq_ready, 'Barbecue ready!.');
var bbq_ready = false;
QUnit.ok(bbq_ready, 'Barbecue ready!.');
Assert

equal(actual, expected, message)
Simple comparison operator (==) to compare the
actual and expected arguments.

var bbq = 'Bacon';
QUnit.equal(bbq, 'Bacon', 'Bacon barbecue!');
QUnit.equal(bbq, 'Chicken', 'Chicken barbecue!');
Assert

notEqual(actual, expected, message)
Simple inverted comparison operator (!=) to
compare the actual and expected arguments.
var bbq = 'Bacon';
QUnit.notEqual(bbq, 'Salad', 'No salad!');
var bbq = 'Salad';
QUnit.notEqual(bbq, 'Salad', 'No salad!');
Assert

deepEqual(actual, expected, message)
Just like equal() when comparing objects, such
that { key: value } is equal to { key: value }.
var bbq = {meat: 'Bacon'};
QUnit.deepEqual(bbq,
{meat: 'Bacon'}, 'Bacon barbecue!');
var bbq = {meat: 'Chicken'};
QUnit.deepEqual(bbq,
{meat: 'Bacon'}, 'Bacon barbecue!');
Assert

notDeepEqual(actual, expected, message)
Just like notEqual() when comparing objects, such
that { key: value } is not equal to { key: value }.
var bbq = {food: 'Bacon'};
QUnit.notDeepEqual(bbq,
{food: 'Salad'}, 'No salad!');
var bbq = {food: 'Salad'};
QUnit.notDeepEqual(bbq,
{food: 'Salad'}, 'No salad!');
Assert

strictEqual(actual, expected, message)
Most rigid comparison of type and value with the
strict equality operator (===).

var bacon = '1';
QUnit.strictEqual(bacon, '1', 'Bacon!');
QUnit.strictEqual(bacon, 1, 'Bacon!');
Assert

notStrictEqual(actual, expected, message)
Most rigid comparison of type and value with the
strict inverted equality operator (!==).

var bacon = '1';
QUnit.notStrictEqual(bacon, 1, 'No Bacon!');
QUnit.notStrictEqual(bacon, '1', 'No Bacon!');
Expect
Expect

expect(amount)
Specify how many assertions are expected to run
within a test. If the number of assertions run does
not match the expected count, the test will fail.
var bbq = 'Bacon';
// Good
QUnit.expect(1);
QUnit.equal(bbq, 'Bacon', 'Bacon barbecue!');
// Wrong
QUnit.expect(1);
QUnit.equal(bbq, 'Bacon', 'Bacon barbecue!');
QUnit.notEqual(bbq, 'Chicken', 'Chicken barbecue!');
Synchronous Testing
Synchronous Testing

// Number of assertions.
QUnit.expect(3);
var bbq_ready = true,
bbq = 'Bacon';
// Assertions.
QUnit.ok(bbq_ready, 'Barbacue is ready!');
QUnit.equal(bbq, 'Bacon', 'Bacon barbecue!');
QUnit.notEqual(bbq, 'Salad', 'No salad!');
Asynchronous Testing
Asynchronous Testing
QUnit.expect(2);
var bbq_ready = false,
bbq = 'Bacon',
time = 36000; // Miliseconds.
QUnit.stop();
setTimeout(function() {
bbq_ready = true;
QUnit.ok(bbq_ready, 'Barbacue is ready!');
QUnit.start();
}, time);
QUnit.equal(bbq, 'Bacon', 'Bacon barbecue!');
Testing User Actions
Testing User Actions
/**
* Implements hook_testswarm_tests().
*/
function bacon_testswarm_tests() {
'bacon_test' => array(
'module' => 'bacon',
'description' => 'Testing bacon.',
'js' => array(
$path . '/tests/bacon.tests.js' => array(),
),
'dependencies' => array(
array('testswarm', 'jquery.simulate'),
),
'path' => 'admin/bacon/test',
'permissions' => array('test bacon')
),
}
Testing User Actions

https://github.com/jquery/jquery-simulate
QUnit.expect(1);
var bbq_ready = false,
bbq = 'Bacon';
bbq_ready.trigger('change');
QUnit.ok(bbq_ready, 'Barbecue ready!');
DEMO
Questions

?
rteijeiro@drewpull.com

More Related Content

DOCX
Cucumber testing
PDF
Cucumber Ru09 Web
PDF
Multi tenant/lang application with Ruby on Rails
PDF
Scaling Deployment at Etsy
PDF
Outside-in Development with Cucumber and Rspec
PPTX
Project 1
PDF
Using Prometheus to monitor your build pipelines
PDF
Test Failed, Then...
Cucumber testing
Cucumber Ru09 Web
Multi tenant/lang application with Ruby on Rails
Scaling Deployment at Etsy
Outside-in Development with Cucumber and Rspec
Project 1
Using Prometheus to monitor your build pipelines
Test Failed, Then...

What's hot (20)

PPT
Auto Build
PDF
Drupal + selenium
PDF
Performance
PDF
Chef-NYC June-2014 - Testing cookbooks on Digital Ocean
PDF
Hand Crafted Artisanal Chef Resources
PPT
Introduccion app engine con python
KEY
I18n
PDF
ChefConf 2016 - Writing Compossible Community Cookbooks using Chef Custom Res...
PDF
Modern infrastructure as code with ansible PyTN
PPTX
Breaking Technology Silos with Chef
PDF
RSpec User Stories
PDF
Selenium: What Is It Good For
PPTX
Frontend testing with Codeception
PDF
Cookbook refactoring & abstracting logic to Ruby(gems)
PDF
Continuous Deployment at Scale, PHPConfAsia 2016
PPTX
anatomy of a crash
PPTX
Put kajakken på hylden - og få sexede windows services
DOCX
Genre research from canva
PDF
Selenium sandwich-3: Being where you aren't.
PDF
Testing Microservices with a Citrus twist
Auto Build
Drupal + selenium
Performance
Chef-NYC June-2014 - Testing cookbooks on Digital Ocean
Hand Crafted Artisanal Chef Resources
Introduccion app engine con python
I18n
ChefConf 2016 - Writing Compossible Community Cookbooks using Chef Custom Res...
Modern infrastructure as code with ansible PyTN
Breaking Technology Silos with Chef
RSpec User Stories
Selenium: What Is It Good For
Frontend testing with Codeception
Cookbook refactoring & abstracting logic to Ruby(gems)
Continuous Deployment at Scale, PHPConfAsia 2016
anatomy of a crash
Put kajakken på hylden - og få sexede windows services
Genre research from canva
Selenium sandwich-3: Being where you aren't.
Testing Microservices with a Citrus twist
Ad

Viewers also liked (6)

PDF
Architecting your Frontend
PDF
Contributing to Drupal 8
PDF
Startup Wars
PDF
Contributing to Drupal 8 - Frankfurt
PDF
ODP
IPC 2013 - High Performance PHP with HipHop
Architecting your Frontend
Contributing to Drupal 8
Startup Wars
Contributing to Drupal 8 - Frankfurt
IPC 2013 - High Performance PHP with HipHop
Ad

More from Ruben Teijeiro (8)

PDF
Headless Drupal 8
PDF
Drupal Heroes
PDF
Front-end Automated Testing
PDF
Drupal Mobile
PDF
Twittalicious - Organiza tus Redes Sociales
PDF
Twittalicious - Desarrollo de un Producto con Drupal
PDF
Metodologia de Trabajo en Proyectos con Drupal
ODP
Drush - More Beer, Less Effort
Headless Drupal 8
Drupal Heroes
Front-end Automated Testing
Drupal Mobile
Twittalicious - Organiza tus Redes Sociales
Twittalicious - Desarrollo de un Producto con Drupal
Metodologia de Trabajo en Proyectos con Drupal
Drush - More Beer, Less Effort

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Cloud computing and distributed systems.
PPTX
A Presentation on Artificial Intelligence
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Machine learning based COVID-19 study performance prediction
PDF
Electronic commerce courselecture one. Pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
Teaching material agriculture food technology
Review of recent advances in non-invasive hemoglobin estimation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Per capita expenditure prediction using model stacking based on satellite ima...
Cloud computing and distributed systems.
A Presentation on Artificial Intelligence
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
Machine learning based COVID-19 study performance prediction
Electronic commerce courselecture one. Pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
NewMind AI Weekly Chronicles - August'25 Week I
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Advanced methodologies resolving dimensionality complications for autism neur...

Drupal8 Front-end Automated Testing