Extension:UnitTest
UnitTest Release status: stable |
|
---|---|
Implementation | Special page |
Description | Provides unit testing with PHPUnit, Selenium and QUnit. |
Author(s) | JpostlethwaiteTalk |
Last version | SVN |
License | GPLv2 |
Download |
Download snapshot[?] (Git | SVN)
Git [?]: repo summary • tree • code changes SVN [?]: checkout-url • tree • code changes |
Check usage (experimental) |
UnitTest provides unit testing with PHPUnit, Selenium and QUnit.
Contents |
[edit] Overview
The goal of this extension is to bridge the gap between Continuous integration and local developer testing (i.e., testing on your workstation).
This extension also allows testing of PHPUnit, Selenium and QUnit in one application, as opposed to having these tested in different applications.
This extension also generates screenshots for a slideshow if Selenium is used in a test. A screenshot will be generated automatically after each assertion. After the test has been run, links are presented to the developer (on the command line) to view the slideshows.
This extension also generates Code Coverage reports in html and XML.
Additional reports are generated which could be picked up by monitoring tools such as Nagios.
[edit] Requirements
- A web server like Apache httpd
- PHP > 5.2
- A database server like MySQL for the Mediawiki instance.
- Git or Subversion to manage code
- Git to pull in PHPUnit
- Xdebug - required for Code Coverage
- Linux | OS X | Unix
[edit] TODO
- Build out a special page for the UnitTest extension
- Allow viewing of unit test slideshows
- Allow cleanup of old slideshows
- See what extensions are using UnitTest
[edit] Installation
Setting up your system for unit testing requires a few external libraries.
The following example is a way to set up your system to work with several virtual web hosts. This makes it possible to test many versions of the same application.
[edit] Directory Structure
You do not need to have this exact structure setup. Any deviations will need to be accounted for in your configuration files.
/www |--bin | `--stylize.php | |--conf | `--httpd | |--sites | | |--default.conf | | |--phpmyadmin.conf | | |--mediawiki.1.20.localhost.example.org.conf | | `--mediawiki.master.localhost.example.org.conf | | | `--httpd.conf | |--github | |--phpunit | |--qunit | `--symfony | |--library | `--phpunit | |--dbunit | |--php-code-coverage | |--php-file-iterator | |--php-text-template | |--php-timer | |--php-token-stream | |--phpunit | |--phpunit-mock-objects | `--phpunit-selenium | `--sites `--localhost |--default |--phpmyadmin |--mediawiki-1.20.localhost.example.org `--mediawiki-master.localhost.example.org
To create this structure on Linux or UNIX:
mkdir -p /www/bin mkdir -p /www/conf/httpd/sites mkdir /www/github mkdir -p /www/library/phpunit-3.6 ln -sn /www/library/phpunit-3.6 /www/library/phpunit mkdir /www/library/seleniumHQ mkdir -p /www/sites/localhost/default/public mkdir /www/sites/localhost/mediawiki-1.20.localhost.wikimedia.org mkdir /www/sites/localhost/mediawiki-master.localhost.wikimedia.org
[edit] PHPUnit
Information about phpunit may be found here:
https://github.com/sebastianbergmann/phpunit/
[edit] Install PHPUnit
cd /www/library/phpunit-3.6 git clone git://github.com/sebastianbergmann/phpunit.git git clone git://github.com/sebastianbergmann/dbunit.git git clone git://github.com/sebastianbergmann/php-file-iterator.git git clone git://github.com/sebastianbergmann/php-text-template.git git clone git://github.com/sebastianbergmann/php-code-coverage.git git clone git://github.com/sebastianbergmann/php-token-stream.git git clone git://github.com/sebastianbergmann/php-timer.git git clone git://github.com/sebastianbergmann/phpunit-mock-objects.git git clone git://github.com/sebastianbergmann/phpunit-selenium.git git clone git://github.com/sebastianbergmann/phpunit-story.git git clone git://github.com/sebastianbergmann/php-invoker.git
Set your checkout to 3.6:
cd phpunit && git checkout 3.6 && cd .. cd dbunit && git checkout 1.1 && cd .. cd php-code-coverage && git checkout 1.1 && cd .. cd phpunit-mock-objects && git checkout 1.1 && cd .. cd phpunit-selenium && git checkout 1.1 && cd ..
[edit] Selenium Server
Selenium Server is used for automated browser testing.
[edit] Install Selenium Server
You may download the file from this link:
http://selenium.googlecode.com/files/selenium-server-standalone-2.21.0.jar
cd /www/library/seleniumHQ wget http://selenium.googlecode.com/files/selenium-server-standalone-2.21.0.jar ln -sn /www/library/seleniumHQ/selenium-server-standalone-2.21.0.jar /www/library/seleniumHQ/selenium-server.jar
[edit] Controlling Selenium Server
When you are ready to test with Selenium Server, you will need to start it from the command line. This will take over the terminal in which you run it, so you will need a second terminal in order to execute the phpunit test.
There is a lot of useful information that will be dumped from selenium-server.jar.
You will see information about browsers being opened and what pages are being hit.
java -jar /www/library/seleniumHQ/selenium-server.jar
There are other ways to install and control Selenium Server. This is just one of many!
[edit] Virtual Web Hosts
The virtual host configuration file is named after the host name with the file extension .conf
[edit] Create the virtual host file
vi /www/conf/httpd/sites/mediawiki-master.localhost.example.org.conf
## mediawiki-master.localhost.example.org <VirtualHost *:80> ServerName mediawiki-master.localhost.example.org ServerAlias mediawiki-master.localhost DocumentRoot "/www/sites/localhost/mediawiki-master.localhost.example.org" <Directory "/www/sites/localhost/mediawiki-master.localhost.example.org"> AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost>
You will need to add an include to pick up the virtual host files. Apache may need additional configuration to enable virtual hosts.
You may not need the default host set, depending on your configuration.
Append this to your httpd.conf, where ever it lives.
vi /www/conf/httpd/httpd.conf
NameVirtualHost *:80 <VirtualHost _default_:80> DocumentRoot "/www/sites/localhost/default/public" <Directory "/www/sites/localhost/default/public"> <IfModule mod_dav.c> DAV Off </IfModule> AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> # Virtual Hists Include /www/conf/httpd/sites/*.conf