Warning: This page has not been updated in over over a year and may be outdated or deprecated.
legacy:vufind_1.x_developer_manual:unit_tests
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
legacy:vufind_1.x_developer_manual:unit_tests [2015/12/14 19:26] – ↷ Links adapted because of a move operation demiankatz | legacy:vufind_1.x_developer_manual:unit_tests [2018/12/19 13:56] (current) – demiankatz | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Unit Tests ====== | ====== Unit Tests ====== | ||
- | //This page refers | + | // This outdated |
- | + | ||
- | //This page is aimed at developers who want to test that their changes have not broken existing VuFind functionality or who are interested in creating standard tests for new VuFind components. | + | |
- | + | ||
- | ===== Background ===== | + | |
- | + | ||
- | The test modules provided with VuFind use the [[http:// | + | |
- | + | ||
- | ===== Location ===== | + | |
- | + | ||
- | The VuFind unit tests can be found in the tests directory of your VuFind installation. | + | |
- | + | ||
- | The layout of the tests directory is designed to mirror the main VuFind application. | + | |
- | + | ||
- | Every directory of the tests directory should contain an AllTests.php file which runs all tests in that directory and in the directory' | + | |
- | + | ||
- | * If you add the first file to a directory, make sure that the directory' | + | |
- | * If you add a new directory, make sure that AllTests.php in the new directory' | + | |
- | + | ||
- | ===== Selenium ===== | + | |
- | + | ||
- | Although most unit tests are intended to test individual features of an application (and this is a good practice whenever possible), VuFind' | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | ==== Setting up Selenium ==== | + | |
- | + | ||
- | In order for the Selenium tests to work, you need to install a couple extra pieces of software: | + | |
- | + | ||
- | * You should download the latest version of the Selenium RC (remote control) package [[http:// | + | |
- | * PHPunit has integrated selenium drivers and hence we extend the " | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | ==== Headless Selenium ==== | + | |
- | Selenium tests will be run in a " | + | |
- | + | ||
- | < | + | |
- | sudo apt-get install xvfb | + | |
- | </ | + | |
- | + | ||
- | To launch a new virtual frame buffer we bind it to display,and export the display variable. | + | |
- | + | ||
- | < | + | |
- | Xvfb -ac :99 | + | |
- | export DISPLAY=: | + | |
- | </ | + | |
- | + | ||
- | To start selenium RC server, we fire the following command in the directory the selenium jar file exists : | + | |
- | < | + | |
- | java -jar selenium-server.jar | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | + | ||
- | ==== Environment Setup ==== | + | |
- | The firefox browser path need to be exported in the PATH and LD_LIBRARY_PATH variables.this can be added to the .profile file. | + | |
- | + | ||
- | < | + | |
- | PATH : / | + | |
- | LD_LIBRARY_PATH : / | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | ==== Running Selenium Tests ==== | + | |
- | + | ||
- | === auto_test.sh === | + | |
- | A script " | + | |
- | + | ||
- | The auto_test.sh script is called from the build.xml file and is executed when phing.sh is started up.It brings up the Xframe buffer and the Selenium RC server.it records their Pids and when after the tests are completed, | + | |
- | + | ||
- | === Test Records === | + | |
- | For the purpose of testing we have a sample of 10 MARC format records which are imported into VUFIND at the beginning of the tests. Tests are fired against these records and at the end of the testing process, the records are deleted from the system.To ensure that the test records are distinctive, | + | |
- | + | ||
- | The sample file " | + | |
- | + | ||
- | === Starting Vufind === | + | |
- | Before you run the Selenium tests, you need to have a running instance of VuFind. | + | |
- | + | ||
- | These tasks make a couple of important assumptions: | + | |
- | + | ||
- | * They only work under Linux; VuFind is not currently designed to be tested under Windows. | + | |
- | * They assume that you have an Ubuntu-style Apache setup, where configuration files can be dropped into a " | + | |
- | + | ||
- | If you look at the top of the build.xml file in the root of VuFind, you will see that there are several parameters that you can override to make the tasks work on your local system. | + | |
- | + | ||
- | < | + | |
- | #!/bin/sh | + | |
- | phing -Dapachectl=" | + | |
- | </ | + | |
- | + | ||
- | Assuming you have this script in place in the root of your VuFind development directory, you can go through the testing process like this: | + | |
- | + | ||
- | < | + | |
- | cd $VUFIND_HOME | + | |
- | ./phing.sh startup | + | |
- | phpunit tests/ | + | |
- | ./phing.sh shutdown | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ==== Building a New Selenium Test ==== | + | |
- | + | ||
- | A base class has been created in tests/ | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | ==== Testing Bugs ==== | + | |
- | Bugs can be tested as part of continuous integration process. | + | |
- | + | ||
- | == Step 1 == | + | |
- | Write the selenium-phpunit based test for the bug. | + | |
- | + | ||
- | == Step 2 == | + | |
- | If the test needs a special MARC record to be reproduced, create one and preferably edit its ID value (in the 001 field) to " | + | |
- | + | ||
- | == Step 3 == | + | |
- | Create a Directory with name " | + | |
- | < | + | |
- | / | + | |
- | </ | + | |
- | + | ||
- | **The directory name must start with word " | + | |
- | + | ||
- | In you Bug# directory place your unit test file and the MARC record (if any). It is recommended that you name your test class SeleniumBugTest# | + | |
- | + | ||
- | < | + | |
- | Example | + | |
- | : | + | |
- | -rwxr-xr-x 1 2096 2011-05-03 13:33 SeleniumBugTest1.php* | + | |
- | -rwxr-xr-x 1 539 2011-05-10 12:34 heb.mrc* | + | |
- | </ | + | |
- | + | ||
- | If necessary, you may have more than one Unit test for a particular Bug or more than one MARC record too (i.e. SeleniumBugTest1a.php, | + | |
---- struct data ---- | ---- struct data ---- | ||
+ | properties.Page Owner : | ||
---- | ---- | ||
legacy/vufind_1.x_developer_manual/unit_tests.txt · Last modified: 2018/12/19 13:56 by demiankatz