Home > Article > Backend Development > What is the use of php unit testing?
php unit testing is a good idea. It provides an automated testing method and makes automated testing possible in agile development.
#php is different from other languages. Unit testing needs to be installed and configured by yourself, which is relatively troublesome. However, unit testing can improve the stability and robustness of the library. It’s still very powerful. Let’s teach you how to configure PHP unit testing (recommended learning: PHP video tutorial)
Note: PHP needs to be upgraded to version 7.1 or above
Configuration instructions
Global installation of phpunit command script
$ wget https://phar.phpunit.de/phpunit-7.0.phar $ chmod +x phpunit-7.0.phar $ sudo mv phpunit-7.0.phar /usr/local/bin/phpunit $ phpunit --version PHPUnit x.y.z by Sebastian Bergmann and contributors.
Global installation of phpunit code
composer global require phpunit/phpunit
Create phpunit.xml and place it in the root directory of your project. This file is a configuration file that phpunit will read by default:
<phpunit bootstrap="vendor/autoload.php"> <testsuites> <testsuite name="service"> <directory>tests</directory> </testsuite> </testsuites> </phpunit>
Configure the phpstorm unit phpunit.phar path, Languages & Frameworks > PHP > PHPUinit
For example, the local path of my phpunit is /usr/local/bin/phpunit
Configure the unit test class Tip, Languages & Frameworks > PHP > include path
For example, the local path of my phpunit package is /Users/chenqionghe/.composer/vendor/phpunit
The above is the detailed content of What is the use of php unit testing?. For more information, please follow other related articles on the PHP Chinese website!