System Testing

From Joomla! Documentation

Revision as of 10:00, 27 May 2010 by Betweenbrain (Talk | contribs)

Quill icon.png
Page Actively Being Edited!

This article is actively undergoing a major edit for a short while.
As a courtesy, please do not edit this page while this message is displayed. The user who added this notice will be listed in the page history. This message is intended to help reduce edit conflicts; please remove it between editing sessions to allow others to edit the page. If this page has not been edited for several hours, please remove this template, or replace it with {{underconstruction}} or {{incomplete}}.

News and Updates

  • 2009 07 27 Document created.
  • 2010 05 24 Added Tips & Tricks section.

System Testing

System testing is an essential part of a good Quality Control program. For a good general discussion of system testing, visit the Wikipedia article.

System Testing in Open Source

Web applications have been notoriously difficult to do system testing with. It has traditionally required a great deal of time and effort. This can be a special challenge for open source projects because testing is often not very popular and designing tests that can be executed in a systematic way even less so. For a complicated application like Joomla!, this means that although we might do testing, we very seldom are able to perform extensive testing on each release that covers even a fraction of the elements in the CMS.

Relatively recently, a project called Selenium has arrived on the scene. This project makes performing automated system testing of web applications possible. This means that it is possible to devise a test and have it performed in an automated way without the requirement of somebody sitting in front of a browser and being a click monkey.

The benefits of system testing are:

  • System tests help highlight cases where changes in one element of the system might cause breakage in other, unexpected areas.
  • System tests help clearly specify how the application should behave.

System Testing versus Unit Testing

In order to fully test an application, both system and unit testing are essential. Each approach has their benefits and weaknesses. Unit testing is very good for isolating small chunks of code and ensuring that they are behaving as expected. System testing, on the other hand, is geared towards looking at the system as a whole and ensuring that the units are behaving together in a way that achieves the desired effect.

The advantages of system testing is that system tests are easier to understand and conceptualize by people who are unfamiliar with the underlying code. With Selenium, tests can be designed by people who are not overly familiar with PHP - they only need to understand the application and what results should be expected.

The downside of system testing is that it will only tell you that something broke. It isn't as obvious with system testing exactly what went wrong or where the problem is.

Test Objects

If the purpose of unit tests is to isolate a module of code, then the purpose of system tests is to evaluate the entire system. This is much easier for those unfamiliar with what happens under the hood of Joomla! because one is not required to understand what happens during a Joomla! page request. A system test might evaluate, for example, if unpublishing an article works properly. Therefore, to design the test, it is only necessary to figure out how to change an article from Published to Unpublished, and how to verify that the article was actually unpublished.

System Testing in Joomla!

I have recently been building a system testing architecture that will make it possible to write tests once, and to execute those tests on a variety of platforms and clients. I currently have infrastructure in place that makes it possible to run one command and execute system tests in one browser on one host system. I have designed the host system in such a way that it will run on 6 different PHP versions (stock Ubuntu PHP 5 and self-compiled PHP 4.3, 4.4, 5.0, 5.1 and 5.2) and 2 different web servers (Apache and Lighttpd). These are all currently serving from the same database.

The future steps will be to make it possible to run on multiple host systems (the requirement for this is to generalize the code that resets the database state after the tests are run) and to make it possible to use different clients (i.e. different systems with different web browsers). These steps should be fairly trivial, but I have not yet had time to focus on them.

This will eventually make it possible to run the designed tests on every major browser and on multiple server platforms (various PHP versions, various configurations, various operating systems and various web servers).

Writing System Tests

Selenium IDE makes it fairly easy to write system tests. It is a Firefox extension that operates as an Integrated Development Environment for creating system tests. In essence, it records your clicks as you navigate in your browser and encodes them into a series of commands that can control the browser. Tests recorded with Selenium IDE can be converted to tests within the Joomla repository and integrated into the test suite.

Getting Selenium IDE

At of May 27, 2010, the latest version of Selenium IDE is 1.0.7. You can get it at Click on the download link and install like you would any Firefox plugin.

Preparing your Environment

To get started, create a clean install of Joomla! with the standard sample data or update your local copy to the latest build and perform a re-installation.

Creating a Basic Test
  1. To start, open Firefox and browse to the home page of your Joomla! install. For example, I setup my install on my localhost, and so the URL is
  2. Click on Tools -> Selenium IDE. You will notice that on the right of the window that appears near the top, that there is a red circle that is highlighted. This is the start/stop recording button. When you start Selenium IDE, recording starts right away.
    • For our first test, we are going to load the home page and check to make sure that all the items in the Main Menu are present.
    • The commands that we use to check that items are present are called assertions. Basically, you perform your actions and make assertions about the results.
    • In our case, we are going to use the command assertText. This command will read the text of a specified element and ensure it matches a particular value.
  3. Ensure that the Base URL displayed in the Selenium IDE window is the home page of your Joomla! install.
  4. Switch to the browser window that has your Joomla install open.
  5. Right click on each menu item and select 'Assert Text'.
  6. Switch to your Selenium IDE window and click the Red Button to stop recording.

You should see two tabs in your Selenium IDE window - one labeled Table, and one labeled Source. You don't really need to look at the Source window.

Our first test is done.

To run your test, you use the icons on the bar between the Base URL address bar and the Table and Source tabs. The two important buttons are the buttons with the Green Triangle with Three Solid rectangles and the one with the Green Triangle and One Solid Rectangle. The first one will execute the entire test suite and the second one will run the currently selected test case. Since we currently have only one test case, both of these currently do the same thing.

To run your test, press one of these buttons.

As you watch the Selenium IDE, you will see a yellow bar move down your list of steps. Once a step is completed, a successfully executed action (i.e. a button was successfully located and clicked) should show up in light green and a successful assertion should show up in darker green. Failed actions show up in light red and failed assertions show up in darker red.

Click on the Window Expander on the left to unhide the Test Case browser.

If your test completed successfully, you should see Runs: 1, Failures: 0 at the bottom of the Test Case browser.

Converting Selenium IDE Tests

Tests recorded with Selenium IDE can be converted for inclusion in the /tests/system folder as well as integration in to the test suite. The basic procedure is as follows:

All converted Selenium IDE tests need to begin with <?php, contain a comment block, require the SeleniumJoomlaTestCase.php by use of require_once 'SeleniumJoomlaTestCase.php'; and then define the test as a new class that extends SeleniumJoomlaTestCase. Defining the test as a class uses the naming convention, written in CamelCase, of:

subject + test number in the series (4 digits) + "Test"

For example, our first test regarding groups would be:

 Group + 0001 + Test

resulting in the final name of


The complete top portion of our tests look like:

 * @version     $Id: group0001Test.php
 * @package     Joomla.SystemTest
 * @copyright   Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * Tests creating and deleting a User Group
require_once 'SeleniumJoomlaTestCase.php';

class Group0001Test extends SeleniumJoomlaTestCase
        function testCreatDeleteGroup()

Once you have this top portion in place, the recorded Selenium IDE test, in PHP format, can be copied and pasted below this portion.

Tips & Tricks

  • Undo all changes your test may make: All tests should make all efforts to leave the sample data and test site content as it was before the test started. In some cases, a test may break due to a change in the test site's content. For example, if you add a test user, delete the test user at the end of your test or series of tests that require that user.
  • Maximize flexibility through test methods: In many tests, similar or identical actions are repeated. In these cases, these actions can be reproduced as a granular test method added to /tests/system/SeleniumJoomlaTestCases.php. Good examples include:
    • doAdminLogin
    • gotoAdmin
    • gotoSite

(see Selenium Test Case Methods)

Running System Tests

Joomla Core Selenium testcases

The testing repository for the Selenium test suite for version 1.5 can be found here:

As of February 2010, the unit and system tests for version1.6 have been incorporated into the SVN trunk under a folder called "tests". More information about running the version 1.6 tests is available in the article Running Automated Tests for Version 1.6.

Note: If a login mask comes up, use

User: anonymous
Password: <empty>

How to Get it Running

Instructions for running the system tests for version 1.6 can be found here: Running Automated Tests for Version 1.6.


Frequently Asked Questions

See also

For writing a more advanced Selenium testcase see here.

Selenium documentation.