joomla! testing - j!dd germany 2016

57
Joomla! Testing Yves Hoppe @yveshoppe @compojoom

Upload: yves-hoppe

Post on 14-Jan-2017

26 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Joomla! Testing - J!DD Germany 2016

Joomla! TestingYves Hoppe

@yveshoppe

@compojoom

Javier Gomez
excellent presentation! congratulations.
Page 2: Joomla! Testing - J!DD Germany 2016

Why?

Deliver better and reliable application

Validate there is no regression

Make sure your application runs as expected

Trust your own application

Makes debugging much easier

Page 3: Joomla! Testing - J!DD Germany 2016

TestsIn Joomla!

Unit testsIntegration testsSystem testsJavaScript testsCodeStyle (phpcs)

Page 4: Joomla! Testing - J!DD Germany 2016

Joomla! Automated Testing Team

Page 5: Joomla! Testing - J!DD Germany 2016

Unit testing

Page 6: Joomla! Testing - J!DD Germany 2016

In Unit testing ()

we test a small and specific amount of code

Page 7: Joomla! Testing - J!DD Germany 2016

Sample method

public function isTheAnswer($number){

if ($number === 42) {

return true; } return false;}

Page 8: Joomla! Testing - J!DD Germany 2016

Sample test

class TestCase extends \PHPUnit\Framework\TestCase{

public function testIsTheAnswer(){

$this->assertTrue(isTheAnswer(42));$this->assertFalse(isTheAnswer(1));

// … Best practice: One assertion per test}}

Javier Gomez
nice and funny! :)
Page 9: Joomla! Testing - J!DD Germany 2016

The issue / reality

public function getTheAnswer($number){ if (is_array($number)) throw new Exception('Arrays not accepted');

if (!is_numeric($number)) // Check

// Decimal, Binary, Hex - @todo add lower / upper case check if ($number === 42 || $number === '00101010' || $number == '2A' || $number == '0x2A') return '<span class="answer-right">The number is the answer to

everything</span>'; elseif ($number == 13) return '<div class="answer-partial">What do you get when you multiple 6 x

9=</div>'; elseif ($number == 666) return 'WTF?!';

return false;}

Page 10: Joomla! Testing - J!DD Germany 2016

Benefits of Unit testing

Issues can be discovered early

Acts as documentation

Forces you to write simpler and more readable code

Verifies the design

Fastest and no GUI necessary

Javier Gomez
another possible benefit: They are the fastests tests to run (and write)
Page 11: Joomla! Testing - J!DD Germany 2016

Drawbacks

Does not show the absence of errors

Hard to set up useful and realistic tests

Writing unit tests after the development can be tough

Does only cover code

Page 12: Joomla! Testing - J!DD Germany 2016

Unit tests in Joomla!

Page 13: Joomla! Testing - J!DD Germany 2016

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

Page 14: Joomla! Testing - J!DD Germany 2016

PHPUnit 4.8.27

Within today 6119 different tests with 10526 assertions

Page 15: Joomla! Testing - J!DD Germany 2016

We need you

Page 16: Joomla! Testing - J!DD Germany 2016

Running the Joomla! unit testsClone the current staging repo from GitHub

git clone --depth 1 https://github.com/joomla/joomla-cms

Navigate with the command line to the cloned joomla instancecd joomla-cms

Install dependencies with composer (get it before)composer install

Run the tests with:‘libraries/vendor/bin/phpunit’

Page 17: Joomla! Testing - J!DD Germany 2016

Value for Joomla! Extension Developers

Page 18: Joomla! Testing - J!DD Germany 2016

Downsides

Complicated to set up with Joomla!

You have to mock and bootstrap everything

Lot of work

Page 19: Joomla! Testing - J!DD Germany 2016

System Tests

Page 20: Joomla! Testing - J!DD Germany 2016

In System Testing (Browser testing)

we test against the installed and running application

Page 21: Joomla! Testing - J!DD Germany 2016

Benefits

Tests the whole application

Real world testsTest more code

with less lines

Page 22: Joomla! Testing - J!DD Germany 2016

System tests vs Unit tests

Unit tests are mainly used to test framework classes

System tests make sure the application works correctly from a user point

System tests does not require you to understand the code (or even the programming language)

System tests test the whole system not only a small part

They also cover JavaScript, CSS and markup changes

It’s not System or Unit testing - they complement each other!

Page 23: Joomla! Testing - J!DD Germany 2016

System tests in Joomla!

https://www.youtube.com/watch?v=ZHo0TuA5Qjs

Page 24: Joomla! Testing - J!DD Germany 2016

Google Summer of Code 2016

Prital Patel

● Setup of browser automated tests for Joomla!

● Powered by Gherkin● For com_users● And com_content

Page 26: Joomla! Testing - J!DD Germany 2016

Software used

Page 27: Joomla! Testing - J!DD Germany 2016

https://github.com/joomla-projects/gsoc16_browser-automated-tests

Page 28: Joomla! Testing - J!DD Germany 2016

Sample Codeception testpublic function administratorCreateWeblink(\Step\Acceptance\weblink $I) { $I->wantToTest('Weblink creation in /administrator/'); $I->doAdministratorLogin();

$I->amOnPage('administrator/index.php?option=com_weblinks'); $I->waitForText('Web Links', '30', ['css' => 'h1']); $I->checkForPhpNoticesOrWarnings();

$I->clickToolbarButton('New'); $I->waitForText('Web Link: New', '30', ['css' => 'h1']); $I->fillField(['id' => 'jform_title'], $this->title); $I->fillField(['id' => 'jform_url'], $this->url); $I->clickToolbarButton('Save & Close');

$I->waitForText('Web Links', '30', ['css' => 'h1']); $I->see('Web link successfully saved', ['id' => 'system-message-container']);

$I->see($this->title, ['id' => 'weblinkList']);}

Page 29: Joomla! Testing - J!DD Germany 2016

Running the Joomla! Browser testsClone the current staging repo from GitHub

git clone --depth 1 https://github.com/joomla-projects/gsoc16_browser-automated-tests

Navigate with the command line to the cloned instance codeception foldercd gsoc16_browser-automated tests/tests/codeception

Install dependencies with composer (get it before)composer install

Configure ‘tests/codeception/acceptance.suite.yml’ and run the tests with:‘tests/codeception/vendor/bin/robo run:tests’

Page 30: Joomla! Testing - J!DD Germany 2016

Value for Joomla! extension developers

Page 31: Joomla! Testing - J!DD Germany 2016

BenefitsFast to setup and you don’t need to mock Joomla!

JoomlaBrowser has common Steps for Joomla, like:

Installation, uninstallation of extensions

Navigation, Checking for PHP notices

Creating menu items

Fast to write and easy to learn

Page 32: Joomla! Testing - J!DD Germany 2016

JavaScript Tests

Page 33: Joomla! Testing - J!DD Germany 2016

In JavaScript Testing (Browser based)

We cover the JavaScript files of our application.

Page 34: Joomla! Testing - J!DD Germany 2016

JavaScript tests in Joomla!

Page 35: Joomla! Testing - J!DD Germany 2016

Google Summer of Code 2016

Ruchiranga Wickramasinghe

● Setup of an automated test system

● Coverage reporting● For /media/system/js● Tests are merged in Joomla!

Core now

Page 36: Joomla! Testing - J!DD Germany 2016

Software used

Page 37: Joomla! Testing - J!DD Germany 2016

Jasmine 2.4.1, Jasmine-jQuery 2.1.1, Karma 0.13.22 and Firefox 48

Within today we have 196 different tests

Page 38: Joomla! Testing - J!DD Germany 2016

Running the JavaScript! testsClone the current staging repo from GitHub

git clone --depth 1 https://github.com/joomla/joomla-cms

Navigate with the command line to your joomla instance javascript tests foldercd joomla-cms/tests/javascript

Install dependencies with npm (get it before)npm install

Run the tests with:‘tests/javascript/node_modules/karma/bin/karma start karma.conf.js’

Page 39: Joomla! Testing - J!DD Germany 2016

Value for Joomla! Extension Developers

Page 40: Joomla! Testing - J!DD Germany 2016

Benefits

No need for mocking Joomla!

No running Joomla! Installation needed

Easy to write and setup

Page 41: Joomla! Testing - J!DD Germany 2016

CodeStyle tests

Page 42: Joomla! Testing - J!DD Germany 2016

Code Styleand Metrics tests(Static Analysis)

check .

Javier Gomez
In case you want to use ISTQB organization language, they call this "Static Analysis":The objective of static analysis is to find defects in software source code and software models. Static analysis is performed without actually executing the software being examined by the tool; dynamic testing does execute the software code. Static analysis can locate defects that are hard to find in dynamic testing. As with reviews, static analysis finds defects rather than failures. Static analysis tools analyze program code (e.g., control flow and data flow), as well as generated output such as HTML and XML.The value of static analysis is:o Early detection of defects prior to test executiono Early warning about suspicious aspects of the code or design by the calculation of metrics, suchas a high complexity measureo Identification of defects not easily found by dynamic testingo Detecting dependencies and inconsistencies in software models such as links o Improved maintainability of code and designo Prevention of defects, if lessons are learned in developmentTypical defects discovered by static analysis tools include:o Referencing a variable with an undefined valueo Inconsistent interfaces between modules and components o Variables that are not used or are improperly declaredo Unreachable (dead) codeo Missing and erroneous logic (potentially infinite loops)o Overly complicated constructso Programming standards violationso Security vulnerabilitieso Syntax violations of code and software modelsStatic analysis tools are typically used by developers (checking against predefined rules or programming standards) before and during component and integration testing or when checking-in code to configuration management tools, and by designers during software modeling. Static analysis tools may produce a large number of warning messages, which need to be well-managed to allow the most effective use of the tool.Compilers may offer some support for static analysis, including the calculation of metrics.
Page 43: Joomla! Testing - J!DD Germany 2016

Why Code Style matters

Communication is the Key

Code looks consistent

Clear rules for developers

Make Errors obvious

Page 44: Joomla! Testing - J!DD Germany 2016

Code Style in Joomla!

http://joomla.github.io/coding-standards/

PHP_CodeSniffer (phpcs)

and PHPQA Tools

Page 45: Joomla! Testing - J!DD Germany 2016

PHP_CodeSniffer 1.5.6 (working on upgrade)

Page 46: Joomla! Testing - J!DD Germany 2016

Running the PHP_CodeSniffer checksClone the current staging repo from GitHub

git clone --depth 1 https://github.com/joomla/joomla-cms

Navigate with the command line to your joomla instance cd joomla-cms

Install dependencies with composer (get it before)composer install

Run the tests with:‘libraries/vendor/bin/phpcs --extensions=php --standard=build/phpcs/Joomla .’

Page 47: Joomla! Testing - J!DD Germany 2016

Automated testing

Page 48: Joomla! Testing - J!DD Germany 2016

Putting the teststogether to a bigautomatic safety net!

Page 49: Joomla! Testing - J!DD Germany 2016
Javier Gomez
lol
Page 50: Joomla! Testing - J!DD Germany 2016

Why?

Repeatable

Detect issues for every commit / pull request

Saves you time and money

Page 51: Joomla! Testing - J!DD Germany 2016

Automated tests in Joomla!

Page 52: Joomla! Testing - J!DD Germany 2016

Software used

Page 53: Joomla! Testing - J!DD Germany 2016

Directly see issues at your Pull Request

Page 54: Joomla! Testing - J!DD Germany 2016

Runs for every change and pull request against coreTravis:

Multiple PHP Versions:

- PHP 5.3, 5.4, 5.5, 5.6, 7.0- 7.1, HHVM (allowed to fail)

JavaScript tests (Node.js)

PHP_CodeSniffer (PHP 5.6)

Page 55: Joomla! Testing - J!DD Germany 2016

Conclusion

Page 56: Joomla! Testing - J!DD Germany 2016

Call for volunteers!

The Joomla! Automated Testing Working Group is looking for new members, which want to make

Joomla! better

https://volunteers.joomla.org/teams/automated-tests-working-group

Page 57: Joomla! Testing - J!DD Germany 2016

Questions?Thank you for listening!

@yveshoppe