单元测试,tp5的单元测试
单元测试官方文档地址:https://phpunit.readthedocs.io/zh_CN/latest/writing-tests-for-phpunit.html
1. 安装单元测试依赖包
我的thinkphp版本为 5.0.23
如果直接使用
composer require topthink/think-testing
会报错
Using version ^2.0 for topthink/think-testing
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
官方文档有一句
https://www.kancloud.cn/manual/thinkphp5/182511
官方的5.0版本的扩展库版本号都是1.*,2.0版本均为ThinkPHP5.1版本专用。
我们指定版本号 v1.0,命令如下,然后安装完成
composer require topthink/think-testing 1.*
2. 编写测试代码
2.1 修改测试代码
测试文件路径 : tp5/tests/
更改:TestCase.php
protected $baseUrl = 'http://www.test.com'; //更换成你本地的host域名
更改 ExampleTest.php
public function testBasicExample()
{
$this->