Olga Evtimova

How to test your Drupal code

Automated Drupal testing

Automated testing is a good practice in software engineering, allowing easier development, easier refactoring and less debugging and mistakes.

Automated testing assists the testing process. The input is provided and assertions are made for the result. In Drupal, two kinds of automated tests can be distinguished: functional tests and unit tests.

In Functional testing user interaction is simulated and the functional specification of the system is verified.

In Unit testing input parameters and expected output are defined in advance. These tests are run several times during the software development. They ensure that the unit is working properly.

How to write automated Drupal tests?

Simpletest is included by default in a Drupal installation. It is very easy to use. PHP script can be used to  run all the tests. Simpletest framework is divided in two parts. One for pure unit tests and another for so called “Web tests”. Web tests are executed in the context of fully loaded Drupal environment. The Simpletest module integrates well with Drupal back-end interface to produce user friendly test result screens. A problem in Simpletest is the lack of Javascript support. Therefore, when Javascript has to be tested, it is better to use Selenium.

Selenium is more complex than Simpletest. It is harder to install and configure. To run tests with Selenium, a graphical user interface, a compatible web browser and a Java Runtime Environment are required. Every new test opens a browser. This means dynamic web pages can be tested, i.e. Javascript. Selenium is very suitable for acceptance testing, allowing you to check whether everything is done correctly and the customer needs are met. The disadvantage of Selenium is its speed – it takes a really long time to perform the tests.

In this article I tried to explain shortly the advantages and disadvantages of both Selenium and Simpletest testing modules. If you have any questions or comments, do not hesitate to contact me.

Comments

  1. software companies indore

    It is really a nice and helpful piece of info. I’m glad that you simply shared this helpful info with us. Please keep us informed like this. Thank you for sharing.

Leave a comment




captcha

Please enter the CAPTCHA text