front-end automated testing

45
Front-end Automated Testing Front-end Automated Testing #drupal-fat #drupal-fat

Upload: ruben-teijeiro

Post on 13-Jan-2015

2.905 views

Category:

Technology


2 download

DESCRIPTION

Actually testing is as important as development and we all want to write code that works. So, why not test our front-end code? To do that we can use some tools as Selenium, Jasmine but I will explain QUnit because it's used in Drupal8 testing. QUnit is a powerful, easy-to-use JavaScript unit testing framework. It's used by the jQuery, jQuery UI, jQuery Mobile projects, also by Drupal, and is capable of testing any generic JavaScript code. Session presented at Drupalcamp Gotemburg 2013 where I explained how to include QUnit testing in our Drupal projects.

TRANSCRIPT

Page 1: Front-end Automated Testing

Front-end Automated TestingFront-end Automated Testing#drupal-fat#drupal-fat

Page 2: Front-end Automated Testing

I don't know what I like

more: Drupal or Beer

@rteijeiro

Ruben TeijeiroRuben Teijeiro

@rteijeiro

Page 3: Front-end Automated Testing

Web DevelopmentWeb Development

Page 4: Front-end Automated Testing
Page 5: Front-end Automated Testing

I'm configuring the server. It will be ready in a few weeks.

Dev OpsDev Ops

Page 6: Front-end Automated Testing

WTF!!

Page 7: Front-end Automated Testing

This design is really fancy. I made it shiny and edgy. Now it pops!!

DesignersDesigners

Page 8: Front-end Automated Testing

So what?

Page 9: Front-end Automated Testing

Content ManagersContent Managers

In-place Content Authoring

Page 10: Front-end Automated Testing

Holy shit!

Page 11: Front-end Automated Testing

We want something like Facebook, but we need it yesterday.

And banners with kittens. Everyone loves kittens.

We should use Comic Sans, it's such a fancy and funny font.

CustomersCustomers

Page 12: Front-end Automated Testing

OMG!!

Page 13: Front-end Automated Testing

BrowsersBrowsers

Page 14: Front-end Automated Testing
Page 15: Front-end Automated Testing

CSSCSS

I said "float: left"!!!

Page 16: Front-end Automated Testing
Page 17: Front-end Automated Testing

RefactoringRefactoring

Fixed Fixed Fixed

Fixed

Fixed Fixed

Fixed

Page 18: Front-end Automated Testing

Final ResultFinal Result

And now I will show you how it looks in Internet Explorer 7

Page 19: Front-end Automated Testing

Nowwhat?!!

Page 20: Front-end Automated Testing

FATFAT

Page 21: Front-end Automated Testing

Front-end Automated TestingFront-end Automated Testing

Because people likes code that works

Page 22: Front-end Automated Testing

Continuous IntegrationContinuous Integration

Page 23: Front-end Automated Testing

● Automated

● Repeteable

● Easy to understand

● Incremental

● Easy to run

● Fast

Unit TestUnit Test

Page 24: Front-end Automated Testing

● QUnit

● Selenium

● Jasmine

● PhantomJS

● YUI Test

Testing ToolsTesting Tools

Page 25: Front-end Automated Testing

QUnitQUnit

Page 26: Front-end Automated Testing

getInfo: function() {

return {

name: 'Drupal Test',

description: 'My first Drupal test',

group: 'Tests'

};

}

Test ConfigurationTest Configuration

Page 27: Front-end Automated Testing

Test ConfigurationTest Configuration

setup: function() {

this.bbq = "Put some bacon here...";

}

Page 28: Front-end Automated Testing

Test ConfigurationTest Configuration

teardown: function() {

this.bbq = "More bacon for the bbq.";

}

Page 29: Front-end Automated Testing

● ok● equal● notEqual● deepEqual● notDeepEqual● strictEqual● notStrictEqual● throws

AssertionsAssertions

Page 30: Front-end Automated Testing

this.bbq = true;

QUnit.ok(this.bbq,

Drupal.t('We have barbecue.'));

QUnit.okQUnit.ok

Page 31: Front-end Automated Testing

this.bbq = 'Bacon';

QUnit.equal(this.bbq, 'Bacon',

Drupal.t('This is a Bacon Barbecue'));

QUnit.equalQUnit.equal

Page 32: Front-end Automated Testing

this.bbq = 'Bacon';

QUnit.notEqual(this.bbq, 'Chicken',

Drupal.t('This is not a Chicken Barbecue'));

QUnit.notEqualQUnit.notEqual

Page 33: Front-end Automated Testing

this.bbq = { meat: 'Bacon' };

QUnit.deepEqual(this.bbq, {meat: 'Bacon' },

Drupal.t('This is a Bacon Barbecue'));

QUnit.deepEqualQUnit.deepEqual

Page 34: Front-end Automated Testing

this.bbq = { meat: 'Chicken' };

QUnit.notDeepEqual(this.bbq, {meat: 'Bacon' },

Drupal.t('This is not a Bacon Barbecue'));

QUnit.notDeepEqualQUnit.notDeepEqual

Page 35: Front-end Automated Testing

this.bbq = 'Bacon';

QUnit.strictEqual(this.bbq, 'Bacon',

Drupal.t('This is a Bacon Barbecue'));

QUnit.strictEqualQUnit.strictEqual

Page 36: Front-end Automated Testing

this.bbq = 5;

QUnit.notStrictEqual(this.bbq, '5',

Drupal.t('This is not a Barbecue for 5'));

QUnit.notStrictEqualQUnit.notStrictEqual

Page 37: Front-end Automated Testing

throws(

function() {

throw "No barbecue."

},

"There is no barbecue."

);

QUnit.throwsQUnit.throws

Page 38: Front-end Automated Testing

Synchronous CallbacksSynchronous Callbacks

QUnit.expect(3);

this.bbq = 'Bacon';

QUnit.ok(this.bbq = 'Bacon', Drupal.t('Bacon barbecue.'));

QUnit.equal(this.bbq, 'Bacon', Drupal.t('Bacon barbecue.'));

QUnit.deepEqual(this.bbq, 'Bacon', Drupal.t('Bacon barbecue.'));

Page 39: Front-end Automated Testing

Asynchronous CallbacksAsynchronous Callbacks

var delay = 1000;

this.bbq = 'Bacon';

QUnit.stop();

setTimeout( function() {

QUnit.ok(this.bbq == 'Bacon', Drupal.t('1 second barbecue.');

QUnit.start();

}, delay);

Page 40: Front-end Automated Testing

Testing User ActionsTesting User Actions

this.bbq.val('Bacon').trigger('keyup');

QUnit.ok(this.bbq.val == 'Bacon',

Drupal.t('Barbecue with keyup.'));

Page 41: Front-end Automated Testing

ResourcesResources

http://drupal.org/project/fat

Page 42: Front-end Automated Testing

TestSwarmTestSwarm

http://drupal.org/project/testswarm

Page 43: Front-end Automated Testing

BrowserStackBrowserStack

http://www.browserstack.com

Page 44: Front-end Automated Testing

DemoDemo

Page 45: Front-end Automated Testing

QuestionsQuestions

?

[email protected]