Warning: This page has not been updated in over over a year and may be outdated or deprecated.
development:testing:unit_tests
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
development:testing:unit_tests [2022/02/14 11:50] – [Mink Tests with Chrome on macOS] emaijala | development:testing:unit_tests [2023/11/28 18:38] (current) – demiankatz | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Unit Tests ====== | ====== Unit Tests ====== | ||
- | //This page is aimed at developers who want to test that their changes have not broken existing | + | //This page is aimed at developers who want to test that their changes have not broken existing |
===== Background ===== | ===== Background ===== | ||
- | The test modules provided with VuFind | + | The test modules provided with VuFind® |
===== Running Tests ===== | ===== Running Tests ===== | ||
Line 11: | Line 11: | ||
==== Important Warnings ==== | ==== Important Warnings ==== | ||
- | These tests were designed for use with VuFind's [[development: | + | These tests were designed for use with VuFind®'s [[development: |
- | The testing process was developed under Linux; this is the recommended platform for VuFind | + | The testing process was developed under Linux; this is the recommended platform for VuFind® |
==== Using Phing ==== | ==== Using Phing ==== | ||
- | The easiest way to run VuFind's tests is with the help of the [[http:// | + | The easiest way to run VuFind®'s tests is with the help of the [[http:// |
=== Recommended setup procedure === | === Recommended setup procedure === | ||
- | 1.) Create a fresh copy of VuFind | + | 1.) Create a fresh copy of VuFind® |
2.) Create a phing.sh script to automatically pass important parameters to Phing (see build.xml for other parameters that may be set here with the -D parameter): | 2.) Create a phing.sh script to automatically pass important parameters to Phing (see build.xml for other parameters that may be set here with the -D parameter): | ||
Line 30: | Line 30: | ||
</ | </ | ||
- | If you are managing multiple | + | If you are managing multiple |
=== Running tests after setup === | === Running tests after setup === | ||
Line 38: | Line 38: | ||
1.) ~/phing.sh startup | 1.) ~/phing.sh startup | ||
- | This command will start up an instance of VuFind | + | This command will start up an instance of VuFind® |
+ | |||
+ | :!: This command may overwrite any existing configuration etc. | ||
2.) ~/phing.sh phpunit | 2.) ~/phing.sh phpunit | ||
Line 54: | Line 56: | ||
3.) ~/phing.sh shutdown | 3.) ~/phing.sh shutdown | ||
- | This command will turn off the VuFind | + | This command will turn off the VuFind® |
+ | |||
+ | :!: This command will reset the installation including configuration and any changes made to files in the git repository. Be sure you save/commit anything important BEFORE you shut down. | ||
=== The Faster Version === | === The Faster Version === | ||
- | If you don't want to run integration tests using a running | + | If you don't want to run integration tests using a running |
~/phing.sh phpunitfast | ~/phing.sh phpunitfast | ||
- | The integration tests will be skipped, but all unit tests not depending on a running | + | The integration tests will be skipped, but all unit tests not depending on a running |
=== Running Just One Test === | === Running Just One Test === | ||
Line 69: | Line 73: | ||
~/phing.sh phpunitfast -Dphpunit_extra_params=$VUFIND_HOME/ | ~/phing.sh phpunitfast -Dphpunit_extra_params=$VUFIND_HOME/ | ||
+ | |||
+ | === Resetting the Setup === | ||
+ | |||
+ | :!: Available from VuFind® 9.1 | ||
+ | |||
+ | If a test, particularly one of the Mink tests described below, gets interrupted e.g. with ctrl-c, it can leave the configuration and/or database of the CI setup in a state that will cause further test runs to fail. In this case you can use the reset_setup command to reset the configuration and database: | ||
+ | |||
+ | ~/phing.sh reset_setup | ||
===== Browser Automation Tests with Mink ===== | ===== Browser Automation Tests with Mink ===== | ||
- | Some of VuFind's tests are designed to use [[http:// | + | Some of VuFind®'s tests are designed to use [[http:// |
If you wish to run this portion of the test suite, revise your phing.sh script (described above) to include some additional variables: | If you wish to run this portion of the test suite, revise your phing.sh script (described above) to include some additional variables: | ||
* extra_shutdown_cleanup - an extra command to run as part of the shutdown process; it's usually a good idea to change the ownership of the local/cache directory here since running tests will cause some files to be owned by Apache, and that will interfere with subsequent file deletion. | * extra_shutdown_cleanup - an extra command to run as part of the shutdown process; it's usually a good idea to change the ownership of the local/cache directory here since running tests will cause some files to be owned by Apache, and that will interfere with subsequent file deletion. | ||
- | * apacheconfdir - a directory from which Apache will auto-load configurations; | + | * apacheconfdir - a directory from which Apache will auto-load configurations; |
* apachectl - the command to restart Apache; you'll probably need to prefix this with sudo to make it work when running tests as a different user | * apachectl - the command to restart Apache; you'll probably need to prefix this with sudo to make it work when running tests as a different user | ||
* dbtype (optional) - defaults to mysql, but can be set to " | * dbtype (optional) - defaults to mysql, but can be set to " | ||
- | * mysqlrootpass (optional) - the MySQL root password (needed for building | + | * mysqlrootpass (optional) - the MySQL root password (needed for building |
- | * vufindurl (optional) - the URL where VuFind | + | * vufindurl (optional) - the URL where VuFind® |
* mink_driver (optional) - the name of the Mink driver to use (e.g. " | * mink_driver (optional) - the name of the Mink driver to use (e.g. " | ||
Line 108: | Line 120: | ||
==== Headless Chrome Testing ==== | ==== Headless Chrome Testing ==== | ||
- | :!: Headless Chrome testing was introduced in VuFind | + | :!: Headless Chrome testing was introduced in VuFind® |
Versions of Chrome 80+ have a built-in remote debugging feature. You can run Chrome instead of the Selenium Server like so: | Versions of Chrome 80+ have a built-in remote debugging feature. You can run Chrome instead of the Selenium Server like so: | ||
Line 120: | Line 132: | ||
==== Troubleshooting ==== | ==== Troubleshooting ==== | ||
- | :!: This section contains some notes that may help you avoid problems when trying to run VuFind's test suite. | + | :!: This section contains some notes that may help you avoid problems when trying to run VuFind®'s test suite. |
- | * Some of VuFind's tests use a record ID containing a slash. In order for these tests to work, your Apache installation needs to be configured with " | + | * Some of VuFind®'s tests use a record ID containing a slash. In order for these tests to work, your Apache installation needs to be configured with " |
* When testing with PostgreSQL, it may be necessary to edit the pg_hba.conf file and change the line "local all all peer" to "local all all md5" to allow password-based database logins required my the test environment. | * When testing with PostgreSQL, it may be necessary to edit the pg_hba.conf file and change the line "local all all peer" to "local all all md5" to allow password-based database logins required my the test environment. | ||
+ | * If you encounter issues with the browser tests, you can try running Chrome without the ''< | ||
+ | * Disable Chrome' | ||
+ | * Set English (US) as the preferred language. | ||
==== Mink Tests with Chrome on macOS ==== | ==== Mink Tests with Chrome on macOS ==== | ||
Line 132: | Line 147: | ||
< | < | ||
- | / | + | / |
</ | </ | ||
Line 150: | Line 165: | ||
=== Required GNU Utilities === | === Required GNU Utilities === | ||
- | :!: Note: This applies only to VuFind | + | :!: Note: This applies only to VuFind® |
- | VuFind's Mink tests up to version 7.x rely on options available only in GNU versions of find, sed and basename, so you will need to install those versions and make sure they are used when running Mink tests on macOS. One option is to use [[https:// | + | VuFind®'s Mink tests up to version 7.x rely on options available only in GNU versions of find, sed and basename, so you will need to install those versions and make sure they are used when running Mink tests on macOS. One option is to use [[https:// |
< | < | ||
Line 163: | Line 178: | ||
PATH="/ | PATH="/ | ||
</ | </ | ||
+ | |||
+ | ==== HTML Validation ==== | ||
+ | |||
+ | It's possible to run Mink tests so that HTML of the final page of each test is validated. You will need to run NU Validator locally for this. NU can be downloaded from https:// | ||
+ | |||
+ | < | ||
+ | java -cp ./vnu.jar -Dnu.validator.servlet.bind-address=127.0.0.1 nu.validator.servlet.Main 8888 | ||
+ | </ | ||
+ | |||
+ | Then run the tests with some extra parameters to enable validation: | ||
+ | |||
+ | < | ||
+ | ./phing.sh phpunitfast -Dhtml_validator=http:// | ||
+ | </ | ||
+ | |||
+ | Results will be written into html_validation.log. It is currently (April 2023) not feasible to use html_validator_fail_tests=1 since there are still some known issues. | ||
+ | |||
+ | ==== Code Coverage ==== | ||
+ | |||
+ | Starting with VuFind® version 9.1 it's possible to collect code coverage data from Mink tests. It is worth noting that gathering coverage data will slow down the tests quite significantly. | ||
+ | |||
+ | Prerequisites: | ||
+ | * Apache must be running on the same server that runs the tests and be able to write to the tmp build directory | ||
+ | * [[https:// | ||
+ | * Remote profiling enabled with '' | ||
+ | |||
+ | :!: Note that enabled PCOV or XDebug in coverage mode will prevent normal debugging with XDebug. | ||
+ | |||
+ | To run tests with coverage enabled, use the phpunit task with the '' | ||
===== Writing Tests ===== | ===== Writing Tests ===== | ||
Line 168: | Line 212: | ||
==== Location ==== | ==== Location ==== | ||
- | VuFind | + | VuFind® |
- | VuFind | + | VuFind® |
- | VuFind | + | VuFind® |
- | The layout of the each test directory is designed to mirror the VuFind | + | The layout of the each test directory is designed to mirror the VuFind® |
==== Support Classes/ | ==== Support Classes/ | ||
Line 180: | Line 224: | ||
The VuFindTest namespace (code found in module/ | The VuFindTest namespace (code found in module/ | ||
- | :!: When working on integration tests, pay special attention to the VuFindTest\Feature\Live* traits (introduced during | + | :!: When working on integration tests, pay special attention to the VuFindTest\Feature\Live* traits (introduced during |
==== Mink Browser Automation ==== | ==== Mink Browser Automation ==== | ||
- | If you want to write browser automation tests, you should extend \VuFindTest\Integration\MinkTestCase. This class will automatically set up the Mink environment for you. It also provides a changeConfigs() method which can be used to reconfigure the running | + | If you want to write browser automation tests, you should extend \VuFindTest\Integration\MinkTestCase. This class will automatically set up the Mink environment for you. It also provides a changeConfigs() method which can be used to reconfigure the running |
Some example Mink tests can be found in [[https:// | Some example Mink tests can be found in [[https:// | ||
- | ==== Local Tests ==== | + | === Guidelines for Writing Mink Tests === |
- | Create a directory in your local module mimicking | + | Here are some guidelines that help create tests that are robust and as fast as possible. MinkTestCase class has several methods that are recommended for interacting with the page. Many of the methods |
- | Prior to vufind 2.2 this will require changes | + | * Use hard-coded snooze only if absolutely necessary. |
+ | * Wait for required conditions | ||
+ | * Wait for something | ||
+ | * Prefer '' | ||
+ | * Use '' | ||
+ | * Close lightbox without further action with '' | ||
+ | * Wait for lightbox to close with '' | ||
+ | * Use '' | ||
+ | * Use '' | ||
+ | |||
+ | ==== Local Tests ==== | ||
+ | Create a directory in your local module mimicking the current structure of the VuFind® tests. The test suite should automatically detect all tests within modules under the VuFind® directory. | ||
===== Related Video ===== | ===== Related Video ===== | ||
See the [[videos: | See the [[videos: | ||
---- struct data ---- | ---- struct data ---- | ||
+ | properties.Page Owner : | ||
---- | ---- | ||
development/testing/unit_tests.1644839453.txt.gz · Last modified: 2022/02/14 11:50 by emaijala