Project

General

Profile

Testing » History » Version 4

Brienne Kordis, 09/23/2022 03:24 PM

1 1 Brienne Kordis
# Testing
2
3
## Writing & Running Unit Tests
4
* 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"
5
    * i.e. testing StuffFinder.php => StuffFinderTest.php
6
* Name the function after the function you are testing, plus "Test"
7
    * i.e. testing findStuff() => findStuffTest()
8
* Can only test public functions
9
    * 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
10
* 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
11 3 Brienne Kordis
* To run a unit test, use this command:
12 1 Brienne Kordis
```
13
env CIVICRM_UF=UnitTests XDEBUG_SESSION=VSCODE phpunit7 (absolute path to file where test is written) --filter (name of test function)
14
```
15 4 Brienne Kordis
*(subbing in the correct content within the parenthesis to the relevant info for your particular test)*