In this session the current automated testing infrastructure of the Joomla CMS is explained:
theory of system- & unit-tests
Joomla's unit testing setup
setting up your machine
how to execute the test suite
how to write a test
Joomla's system testing setup
setting up your machine
how to execute the test suite
how Joomla automates the automated tests
9. A unit test is an automated piece of code that
invokes a unit of work in the system and then
checks a single assumption about the
behavior of that unit of work.
UNIT TEST
11. System testing is testing conducted on a
complete, integrated system to evaluate the
system's compliance with its specified
requirements.
SYSTEM TEST
27. 05. How to write a test : best practices
<?php
class Foo
{
public function bar($string)
{
if (is_int($string))
{
return false;
}
$string = strtoupper($string);
return $string;
}
}
(Unit-)Testing for Joomla David Jardin
28. 05. How to write a test : best practices
<?php
class FooTest extends TestCase
{
public function testBar()
{
$object = new foo();
$this->assertEquals('EXAMPLE', $object->bar('example'));
$this->assertEquals(false, $object->bar(4));
}
}
(Unit-)Testing for Joomla David Jardin
30. 05. How to write a test : best practices
<?php
class FooTest extends TestCase
{
public function testBar1()
{
$object = new foo();
$this->assertEquals('EXAMPLE', $object->bar('example'));
}
public function testBar2()
{
$object = new foo();
$this->assertEquals(false, $object->bar(4));
}
}
(Unit-)Testing for Joomla David Jardin
32. 05. How to write a test : best practices
<?php
class FooTest extends TestCase
{
public function testStringIsConvertedToUppercase()
{
$object = new foo();
$this->assertEquals('EXAMPLE', $object->bar('example'));
}
public function testFalseIsReturnedWhenIntIsUsedAsArgument()
{
$object = new foo();
$this->assertEquals(false, $object->bar(4));
}
}
(Unit-)Testing for Joomla David Jardin
34. 05. How to write a test : best practices
<?php
class FooTest extends TestCase
{
public function testStringIsConvertedToUppercase()
{
$object = new foo();
// assertSame is type safe, so in this case only strings are accepted
$this->assertSame('EXAMPLE', $object->bar('example'));
}
public function testFalseIsReturnedWhenIntIsUsedAsArgument()
{
$object = new foo();
// reduced code
$this->assertFalse($object->bar(4));
}
}
(Unit-)Testing for Joomla David Jardin
43. 07. Setting up your machine
(Unit-)Testing for Joomla David Jardin
44. 07. Setting up your machine
git clone https://github.com/joomla-projects/joomla-systemtest-env.git
cd joomla-systemtest-env
docker build -t joomlasystest-env .
(Unit-)Testing for Joomla David Jardin
46. 08. Running the system test suite
docker run -i -t
-e REPO=https://github.com/joomla/joomla-cms joomlasystest-env
-e BRANCH=stating
(Unit-)Testing for Joomla David Jardin
47. 08. Running the system test suite
(Unit-)Testing for Joomla David Jardin