Unit Testing

From PmaWiki
(Redirected from UnitTesting)
Jump to: navigation, search

This is a first draft...feel free to elaborate.

phpMyAdmin has two types of unit tests build on PHPUnit:

  • Classic unit tests
  • Browser scenarios (run via Selenium RC, introduced in phpMyAdmin 3.3)

Contents

[edit] PHP Unit

[edit] Setup

See: TestingEnvironment

[edit] Configuration files

bootstrap.php

This file runs before starting test and contain all general code that should run before tests.

<?php
 
// Adding phpMyAdmin sources to include path
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(realpath("../index.php");

// Setting constants for testing
define('PHPMYADMIN', 1);
define('TESTSUITE', 1);

session_start();

// You can put some additional code that should run before tests here

?>


phpunit.xml

phpUnit configuation located in file phpunit.xml.dist. In this file located all configuration related for automated testing

  • Organization of TestSuites
  • Selenium browsers configuration
  • Type of logging that phpUnit needs to create
  • php.ini settings, constants and globals variables

More detailed information could be found in PHPUnit official documentation - [1].


Personal configuration files

In repository located files phpunit.xml.dist and test\bootstrap-dist.php that used by default by Continious Integration server.

Developers may made a local copy of this files - bootstrap.php and phpunit.xml. And make it specific for they developer environment.


[edit] Running tests

You can run PHPUnit test from command line for whole suite.

$ cd <pma_dir>
$ phpunit
PHPUnit 3.5.13 by Sebastian Bergmann.

...............................................................  63 / 317 ( 19%)
.............SSSSS............................................. 126 / 317 ( 39%)
............................................................... 189 / 317 ( 59%)
............................................................... 252 / 317 ( 79%)
............................................................SSS 315 / 317 ( 99%)
SS

Time: 4 seconds, Memory: 28.50Mb

Or for specific test

$ phpunit test/libraries/core/PMA_isValid_test.php

Also you can specify configuration files for PHPUnit

$ phpunit -c my_phpunit.xml --bootstrap my_bootstrap.php

And include or exclude specific groups.

$ phpunit --list-groups
PHPUnit 3.5.13 by Sebastian Bergmann.

Available test group(s):
 - Selenium
 - __nogroup__
 - common.lib-tests

And for example exclude Selenium tests.

$ phpunit --exclude-group Selenium


From a browser.

The test/ directory is protected by .htaccess file. Please refer to test\README file for details howto allow http access to this directory.

And then you can run test from browser:

  • <pma_dir>/test/wui.php


[edit] Test Class structure

TODO: link to phpdoc ?

The following class hierarchy is used:

  • PHPUnit_Framework_TestCase
    • PHPUnit_Extensions_SeleniumTestCase
      • PmaSeleniumTestCase
        • PmaSeleniumLoginTest
    • PmaTestCase
      • PmaMessageTest
Personal tools