php与其他语言不太一样,单元测试需要自己安装和配置,相对麻烦一点,不过单元测试对于提高库的稳定性和健壮性还是非常给力的,下面教大家怎么配置PHP单元测试 (推荐学习:PHP视频教程)
注意:php需升级到7.1版本以上
配置说明
全局安装phpunit命令脚本
$ 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.
全局安装安装phpunit代码
composer global require phpunit/phpunit
创建 phpunit.xml放在你的项目根目录,这个文件是 phpunit 会默认读取的一个配置文件:
<phpunit bootstrap="vendor/autoload.php"> <testsuites> <testsuite name="service"> <directory>tests</directory> </testsuite> </testsuites> </phpunit>
配置phpstorm单元phpunit.phar路径,Languages & Frameworks > PHP > PHPUinit
如我的phpunit本地的路径为/usr/local/bin/phpunit
配置单元测试类提示,Languages & Frameworks > PHP > include path
如我的phpunit包本地的路径为/Users/chenqionghe/.composer/vendor/phpunit
Copyright © 2019- fenyunshixun.cn 版权所有 湘ICP备2023022495号-9
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务