About Features Downloads Getting Started Documentation Events Support GitHub

Love VuFind®? Consider becoming a financial supporter. Your support helps build a better VuFind®!

Site Tools


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.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
development:testing:unit_tests [2023/11/28 18:34] – [Troubleshooting] demiankatzdevelopment:testing:unit_tests [2023/11/28 18:38] (current) demiankatz
Line 136: Line 136:
   * 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 "AllowEncodedSlashes on" set in the VirtualHost used for running the VuFind® instance being tested.   * 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 "AllowEncodedSlashes on" set in the VirtualHost used for running the VuFind® instance being tested.
   * 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 ''--headless'' parameter to make the process visible. It's also possible to step through the tests with a PHP debugger if the XDebug extension is installed while checking the results in the visible window. There are a couple of prerequisites for the tests to work properly when running with a visible Chrome window:+  * If you encounter issues with the browser tests, you can try running Chrome without the ''<nowiki>--headless</nowiki>'' parameter to make the process visible. It's also possible to step through the tests with a PHP debugger if the XDebug extension is installed while checking the results in the visible window. There are a couple of prerequisites for the tests to work properly when running with a visible Chrome window:
     * Disable Chrome's "Warn you if passwords are exposed in a data breach" in Privacy and Security settings while running the tests so that the password checks don't interfere with patron tests.     * Disable Chrome's "Warn you if passwords are exposed in a data breach" in Privacy and Security settings while running the tests so that the password checks don't interfere with patron tests.
     * Set English (US) as the preferred language.     * Set English (US) as the preferred language.
Line 216: Line 216:
 VuFind® integration tests (which check the interaction of components in a real running system) can be found in the module/VuFind/tests/integration-tests directory of your VuFind® installation. VuFind® integration tests (which check the interaction of components in a real running system) can be found in the module/VuFind/tests/integration-tests directory of your VuFind® installation.
  
-VuFind® support modules (VuFindHttp, etc.) have their own tests directories, but these are configured to be run automatically as part of VuFind®'s main test suite.+VuFind® support modules (VuFindSearch, etc.) have their own tests directories, but these are configured to be run automatically as part of VuFind®'s main test suite.
  
-The layout of the each test directory is designed to mirror the VuFind module's src directory (module/VuFind/src/VuFind).  Tests should be placed in a directory that corresponds with the component being tested.  For example, the unit tests for the \VuFind\Date\Converter class are found in "module/VuFind/tests/unit-tests/src/VuFindTest/Date/ConverterTest.php".+The layout of the each test directory is designed to mirror the VuFind® module's src directory (module/VuFind/src/VuFind).  Tests should be placed in a directory that corresponds with the component being tested.  For example, the unit tests for the \VuFind\Config\Writer class are found in "module/VuFind/tests/unit-tests/src/VuFindTest/Config/WriterTest.php".
  
 ==== Support Classes/Traits ==== ==== Support Classes/Traits ====
Line 224: Line 224:
 The VuFindTest namespace (code found in module/VuFind/src/VuFindTest) contains several classes and traits which may be useful in writing new tests -- a fake record driver in VuFindTest\RecordDriver, some helpful traits in VuFindTest\Feature, and some base test classes containing reusable patterns in VuFindTest\Unit. The VuFindTest namespace (code found in module/VuFind/src/VuFindTest) contains several classes and traits which may be useful in writing new tests -- a fake record driver in VuFindTest\RecordDriver, some helpful traits in VuFindTest\Feature, and some base test classes containing reusable patterns in VuFindTest\Unit.
  
-:!: When working on integration tests, pay special attention to the VuFindTest\Feature\Live* traits (introduced during VuFind 8 development), which provide helpful methods for retrieving services that provide access to the real database and Solr instances for tests where actual data needs to be manipulated. Such tests should be written with caution, and should only be run in a safe test environment, as noted elsewhere.+:!: When working on integration tests, pay special attention to the VuFindTest\Feature\Live* traits (introduced during VuFind® 8 development), which provide helpful methods for retrieving services that provide access to the real database and Solr instances for tests where actual data needs to be manipulated. Such tests should be written with caution, and should only be run in a safe test environment, as noted elsewhere.
  
 ==== 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 VuFind instance by modifying its .ini files. Any changes made by this method will be automatically rolled back at the end of the test, so you can test a variety of configurations in a single test class.+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 VuFind® instance by modifying its .ini files. Any changes made by this method will be automatically rolled back at the end of the test, so you can test a variety of configurations in a single test class.
  
 Some example Mink tests can be found in [[https://github.com/vufind-org/vufind/tree/dev/module/VuFind/tests/integration-tests/src/VuFindTest/Mink|module/VuFind/tests/integration-tests/src/VuFindTest/Mink/]]. Some example Mink tests can be found in [[https://github.com/vufind-org/vufind/tree/dev/module/VuFind/tests/integration-tests/src/VuFindTest/Mink|module/VuFind/tests/integration-tests/src/VuFindTest/Mink/]].
Line 248: Line 248:
 ==== Local Tests ==== ==== 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.+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 =====
  
development/testing/unit_tests.1701196458.txt.gz · Last modified: 2023/11/28 18:34 by demiankatz