Project

General

Profile

Actions

Testing » History » Revision 1

Revision 1/6 | Next »
Brienne Kordis, 09/23/2022 03:22 PM


Testing

Writing & Running Unit Tests

  • Make a new file in the tests folder of the working directory. The file should be named after the file in which you are testing plus "Test"
    • i.e. testing StuffFinder.php => StuffFinderTest.php
  • Name the function after the function you are testing, plus "Test"
    • i.e. testing findStuff() => findStuffTest()
  • Can only test public functions
    • if needed, step through the call stack to find a public function that is higher up in the stack than the desired private/protected function you want to test
  • Whenever possible, it is best not to rely on an API call for a test, as it can introduce intentional complications that cause the test to fail when the part you're testing should pass
  • To run a unit test, use this command, subbing in the correct path: env CIVICRM_UF=UnitTests XDEBUG_SESSION=VSCODE phpunit7 (absolute path to file where test is written) --filter (name of test function)
    • *note to change the content within the parenthesis to what is indicated relevant to your particular test)

Updated by Brienne Kordis about 2 years ago · 1 revisions