Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Joomla! Testing - J!DD Germany 2016

243 views

Published on

Slides from the Joomla! Day Germany 2016

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

Published in: Engineering
  • Be the first to comment

  • Be the first to like this

Joomla! Testing - J!DD Germany 2016

  1. 1. Joomla! Testing Yves Hoppe @yveshoppe@compojoom
  2. 2. 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
  3. 3. Tests In Joomla! Unit tests Integration tests System tests JavaScript tests CodeStyle (phpcs)
  4. 4. Joomla! Automated Testing Team
  5. 5. Unit testing
  6. 6. In Unit testing() we test a small and specific amount of code
  7. 7. Sample method public function isTheAnswer($number) { if ($number === 42) { return true; } return false; }
  8. 8. Sample test class TestCase extends PHPUnitFrameworkTestCase { public function testIsTheAnswer() { $this->assertTrue(isTheAnswer(42)); $this->assertFalse(isTheAnswer(1)); // … Best practice: One assertion per test } }
  9. 9. 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; }
  10. 10. 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
  11. 11. 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
  12. 12. Unit tests in Joomla!
  13. 13. https://github.com/joomla/joomla-cms/tree/staging/tests/unit
  14. 14. PHPUnit 4.8.27 Within today 6119 different tests with 10526 assertions
  15. 15. We need you
  16. 16. Running the Joomla! unit tests Clone 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 instance cd joomla-cms Install dependencies with composer (get it before) composer install Run the tests with:
  17. 17. Value for Joomla! Extension Developers
  18. 18. Downsides Complicated to set up with Joomla! You have to mock and bootstrap everything Lot of work
  19. 19. System Tests
  20. 20. In System Testing(Browser testing) we test against the installed and running application
  21. 21. Benefits Tests the whole application Real world tests Test more code with less lines
  22. 22. 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
  23. 23. System tests in Joomla! https://www.youtube.com/watch?v=ZHo0TuA5Qjs
  24. 24. Google Summer of Code 2016 Prital Patel ● Setup of browser automated tests for Joomla! ● Powered by Gherkin ● For com_users ● And com_content
  25. 25. Software used
  26. 26. https://github.com/joomla-projects/gsoc16_browser-automated-tests
  27. 27. Sample Codeception test public function administratorCreateWeblink(StepAcceptanceweblink $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']); }
  28. 28. Running the Joomla! Browser tests Clone 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 folder cd 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:
  29. 29. Value for Joomla! extension developers
  30. 30. Benefits Fast 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
  31. 31. JavaScript Tests
  32. 32. In JavaScript Testing(Browser based) We cover the JavaScript files of our application.
  33. 33. JavaScript tests in Joomla!
  34. 34. 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
  35. 35. Software used
  36. 36. Jasmine 2.4.1, Jasmine-jQuery 2.1.1, Karma 0.13.22 and Firefox 48 Within today we have 196 different tests
  37. 37. Running the JavaScript! tests Clone 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 folder cd joomla-cms/tests/javascript Install dependencies with npm (get it before) npm install Run the tests with:
  38. 38. Value for Joomla! Extension Developers
  39. 39. Benefits No need for mocking Joomla! No running Joomla! Installation needed Easy to write and setup
  40. 40. CodeStyle tests
  41. 41. Code Style and Metrics tests(Static Analysis) check .
  42. 42. Why Code Style matters Communication is the Key Code looks consistent Clear rules for developers Make Errors obvious
  43. 43. Code Style in Joomla! http://joomla.github.io/coding-standards/ PHP_CodeSniffer (phpcs) and PHPQA Tools
  44. 44. PHP_CodeSniffer 1.5.6 (working on upgrade)
  45. 45. Running the PHP_CodeSniffer checks Clone 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:
  46. 46. Automated testing
  47. 47. Putting the tests together to a big automatic safety net!
  48. 48. Why? Repeatable Detect issues for every commit / pull request Saves you time and money
  49. 49. Automated tests in Joomla!
  50. 50. Software used
  51. 51. Directly see issues at your Pull Request
  52. 52. Runs for every change and pull request against core Travis: 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)
  53. 53. Conclusion
  54. 54. 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
  55. 55. Questions? Thank you for listening! @yveshoppe

×