Developers (and contributors) of the platform should use a test-driven development approach.
The platform's test suite comprises the following:
Ushahidi platform tests are located in the Ushahidi_Web/tests directory.
Functional tests mainly target the controllers. Their main purpose is to verify that the controllers respond in a certain fashion when supplied with a specific set of parameters via HTTP POST or HTTP GET. The expected behavior could be: displaying a specific message or HTML element, redirecting the user to another page, show/hide a DOM node etc. More information on what Selenium can be used for can be found here here.
As already mentioned above, the unit testing component of the test suite is based on PHPUnit. Therefore, in order to write and run unit tests, PHPUnit (v3.5.4 and above) be installed and added to the include path of your PHP development environment. Conventionally, PHPUnit is installed via PHP PEAR.
NOTE: If you already have PHP PEAR installed, you may skip this section.
Assumption: PHP is already installed (via Macports, Homebrew etc) and the executable has been added to the system $PATH
curl http://pear.php.net/go-pear.phar > pear.php sudo php -q pear.php |
Change the installation base (item 1) to /usr/local. Use the default values for the other options.
In /etc/php.ini change
;include_path = ".:/php/includes" |
to
include_path = ".:/usr/local/share/pear" |
Then restart apache.
sudo apachectl restart |
sudo apt-get install php-pear |
yum -y install php-pear |
sudo pear channel-discover pear.phpunit.de sudo pear channel-discover components.ez.no sudo pear channel-discover pear.symfony-project.com sudo pear install --alldeps phpunit/PHPUnit sudo pear install --alldeps phpunit/dbUnit |
Unit tests are located in the Ushahidi_Web/tests/phpunit
directory.
This directory is organized as follows:
Ushahidi_Web/ |--- tests | |---phpunit/ | |---bootstrap.php | |---classes/ | | |---helpers | | |---hooks | | |---libraries | | |---models | |---data | |---phpunit.xml.template | |---testbootstrap.php |
To run the current battery of tests bundled with the platform, perform the following:
phpunit.xml
from phpunit.xml.template
and save it in Ushahidi_Web/tests/phpunit
. This XML file specifies the following:
boostrap.php
in this case. The bootstrap file ensures that the test cases have access to the Kohana APIapplication/logs
is writable by the PHPUnit executable (phpunit
) otherwise the tests will failtests/phpunit
)
phpunit --stderr |
More information on the various parameters for the XML configuration file can he found here
Unit tests are mainly target helpers, hooks, libraries and models; pieces of code that are re-used/referenced within the platform.
All unit tests must sub-class PHPUnit_Framework_TestCase
(in one way or another). Also, the tests do not have a naming convention per se except for the fact that all the testcase files are in upper case and the suffix of the file is always Test.