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
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. 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. 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. 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
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:
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. System tests in Joomla!
https://www.youtube.com/watch?v=ZHo0TuA5Qjs
24. Google Summer of Code 2016
Prital Patel
● Setup of browser automated
tests for Joomla!
● Powered by Gherkin
● For com_users
● And com_content
29. 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:
31. 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
35. 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
38. 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:
46. 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:
56. 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