Testing » History » Revision 5
Revision 4 (Brienne Kordis, 09/23/2022 03:24 PM) → Revision 5/6 (Brienne Kordis, 09/23/2022 03:29 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:
```
env CIVICRM_UF=UnitTests XDEBUG_SESSION=VSCODE phpunit7 (absolute path to file where test is written) --filter (name of test function)
```
*(subbing in the correct content within the parenthesis to the relevant info for your particular test)*