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
development:testing:unit_tests [2023/11/28 18:36] – [Location] demiankatzdevelopment:testing:unit_tests [2023/11/28 18:38] (current) demiankatz
Line 218: Line 218:
 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. 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\Config\Writer class are found in "module/VuFind/tests/unit-tests/src/VuFindTest/Config/WriterTest.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.txt · Last modified: 2023/11/28 18:38 by demiankatz