joomla! javascript testing

44
Joomla! JavaScript Testing

Upload: thanuditha-ruchiranga-wickramasinghe

Post on 08-Apr-2017

88 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Joomla! JavaScript Testing

Joomla! JavaScript Testing

Page 2: Joomla! JavaScript Testing

Hello!I am RuchirangaComputer Science and Engineering undergraduate at University of Moratuwa, Sri Lanka.

GSoC ‘16 student at Joomla!

You can find me at:@thanurw

Page 3: Joomla! JavaScript Testing

Project mentors

Yves Hoppe

Ashan Fernando

Page 4: Joomla! JavaScript Testing

1.What is Software Testing

In a broad sense

Page 5: Joomla! JavaScript Testing

“Testing is the process of

evaluating a system or its component(s) with the intent to find whether it satisfies the specified requirements or not.

Source: www.tutorialspoint.com/software_testing

Page 6: Joomla! JavaScript Testing

Benefits

▷ Proof of functionality

▷ Confidence▷ Early fault

detection▷ Reduced rework &

cost▷ No “works for me,

dunno about you”

Page 7: Joomla! JavaScript Testing

Drawbacks

▷ Cannot show absence of faults

▷ Setup overhead▷ Need to write

testable code▷ Covers only the

code

Page 8: Joomla! JavaScript Testing

2.Testing in Joomla!

What has been there so far

Page 9: Joomla! JavaScript Testing

Code distribution

Page 10: Joomla! JavaScript Testing

joomla-cms/tests/unithttps://github.com/joomla/joomla-cms/tree/staging/tests/unit

Page 11: Joomla! JavaScript Testing

Travis log7872 different tests and 10266 assertions so far

Page 12: Joomla! JavaScript Testing

3.JavaScript Testing

Why bother?

Page 13: Joomla! JavaScript Testing

A real world examplehttps://issues.joomla.org/tracker/joomla-cms/10259

Page 14: Joomla! JavaScript Testing
Page 15: Joomla! JavaScript Testing

Commit made in 2014Issue found in 2016!

Page 16: Joomla! JavaScript Testing

“To err is human, to forgive is

divine

Page 17: Joomla! JavaScript Testing

IF we had JS tests

▷The issue would have been found in 2014

▷The issue would have been solved in 2014

▷This issue post will not appear in 2016

▷A lot of time and effort could have been saved!

Page 18: Joomla! JavaScript Testing

4.Joomla! JavaScript

Testing ProjectWhat have we achieved so far?

Page 19: Joomla! JavaScript Testing

Jasmine for the rescue!Jasmine as the testing framework

Page 20: Joomla! JavaScript Testing

The Technology stack

▷Jasmine Framework▷Karma test runner▷Travis CI

Page 21: Joomla! JavaScript Testing

And some more...

▷jQuery▷Jasmine jQuery▷RequireJS▷RequireJS Text▷Karma coverage reporter

Page 22: Joomla! JavaScript Testing

Our process is easy

JS tests written using Jasmine

Run with Karma locally

Run on Travis

Page 23: Joomla! JavaScript Testing

Tests written using Jasmine

Page 24: Joomla! JavaScript Testing

Tests run locally using Karma

Page 25: Joomla! JavaScript Testing

Tests run on Travis

Page 26: Joomla! JavaScript Testing
Page 27: Joomla! JavaScript Testing

Covered 10 libraries so farFound in joomla-cms/media/system/js/ directory

Page 28: Joomla! JavaScript Testing

File hierarchykarma.conf.js

tests

javascript

caption

package.json

test-main.js

fixtures

spec-setup.js

spec.js

fixture.html

Page 29: Joomla! JavaScript Testing

Inside

▷ Fixtures

▷ Spec-setup.js

▷ spec.js

Page 30: Joomla! JavaScript Testing

Running the tests locally

▷Clone the repository▷Open a CMD window▷Navigate to tests/javascript▷Execute command npm install▷Execute command npm test

Need to have NodeJS installed

Page 31: Joomla! JavaScript Testing
Page 32: Joomla! JavaScript Testing

5.Joomla! JavaScript

Testing The magic inside!

Page 33: Joomla! JavaScript Testing

Karma configuration

▷Which files to be served, included in browser and watched

▷Configurations : plugins, reporters etc.

▷Single run or not

Page 34: Joomla! JavaScript Testing

More on what happens inside...

▷Karma loads all specified files, delegates specific inclusions to require.js (test-main.js)

▷Require.js dynamically handle dependencies; both code & fixtures

Page 35: Joomla! JavaScript Testing

Require.js configuration

▷test-main.js found in tests/javascript

▷Allow specification of aliases for different paths and files

▷Allows specification of dependencies among them

Page 36: Joomla! JavaScript Testing

6.Let’s see a

demonstrationHow to write JavaScript tests

Page 37: Joomla! JavaScript Testing
Page 38: Joomla! JavaScript Testing

7.Documentation

https://docs.joomla.org/Running_Automated_Tests_for_the_Joomla_C

MS

Page 39: Joomla! JavaScript Testing

7.Is your code testable?

How to write testable code

Page 40: Joomla! JavaScript Testing

Is this testable?(function ($) {

var testable = false;

if (testable) {

$('#content').html("Go home");

} else {

$('#content').html("You are

drunk");

}

})(jQuery)

Page 41: Joomla! JavaScript Testing

How about this?

$(document).ready(function ($)

{

$('#content').hide();

});

Page 42: Joomla! JavaScript Testing

8.An open invitation

For all of you

Page 43: Joomla! JavaScript Testing
Page 44: Joomla! JavaScript Testing

Thanks!Any questions?You can find me at:@[email protected]