View
89
Download
0
Embed Size (px)
Citation preview
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
Project mentors
Yves Hoppe
Ashan Fernando
1.What is Software Testing
In a broad sense
“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
Benefits
▷ Proof of functionality
▷ Confidence▷ Early fault
detection▷ Reduced rework &
cost▷ No “works for me,
dunno about you”
Drawbacks
▷ Cannot show absence of faults
▷ Setup overhead▷ Need to write
testable code▷ Covers only the
code
2.Testing in Joomla!
What has been there so far
Code distribution
joomla-cms/tests/unithttps://github.com/joomla/joomla-cms/tree/staging/tests/unit
Travis log7872 different tests and 10266 assertions so far
3.JavaScript Testing
Why bother?
A real world examplehttps://issues.joomla.org/tracker/joomla-cms/10259
Commit made in 2014Issue found in 2016!
“To err is human, to forgive is
divine
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!
4.Joomla! JavaScript
Testing ProjectWhat have we achieved so far?
Jasmine for the rescue!Jasmine as the testing framework
The Technology stack
▷Jasmine Framework▷Karma test runner▷Travis CI
And some more...
▷jQuery▷Jasmine jQuery▷RequireJS▷RequireJS Text▷Karma coverage reporter
Our process is easy
JS tests written using Jasmine
Run with Karma locally
Run on Travis
Tests written using Jasmine
Tests run locally using Karma
Tests run on Travis
Covered 10 libraries so farFound in joomla-cms/media/system/js/ directory
File hierarchykarma.conf.js
tests
javascript
caption
package.json
test-main.js
fixtures
spec-setup.js
spec.js
fixture.html
Inside
▷ Fixtures
▷ Spec-setup.js
▷ spec.js
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
5.Joomla! JavaScript
Testing The magic inside!
Karma configuration
▷Which files to be served, included in browser and watched
▷Configurations : plugins, reporters etc.
▷Single run or not
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
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
6.Let’s see a
demonstrationHow to write JavaScript tests
7.Documentation
https://docs.joomla.org/Running_Automated_Tests_for_the_Joomla_C
MS
7.Is your code testable?
How to write testable code
Is this testable?(function ($) {
var testable = false;
if (testable) {
$('#content').html("Go home");
} else {
$('#content').html("You are
drunk");
}
})(jQuery)
How about this?
$(document).ready(function ($)
{
$('#content').hide();
});
8.An open invitation
For all of you
Thanks!Any questions?You can find me at:@[email protected]