Testing » History » Version 1
Brienne Kordis, 09/23/2022 03:22 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 | * To run a unit test, use this command, subbing in the correct path: |
||
12 | ``` |
||
13 | env CIVICRM_UF=UnitTests XDEBUG_SESSION=VSCODE phpunit7 (absolute path to file where test is written) --filter (name of test function) |
||
14 | ``` |
||
15 | * *note to change the content within the parenthesis to what is indicated relevant to your particular test) |