🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
laravel 单元测试文档 :https://learnku.com/docs/laravel/8.5/testing/10415#c45cc6 目录中 根目录中的test中 ![](https://img.kancloud.cn/58/4d/584d3531860a09a5d9596f9313842364_676x115.png) feature 功能测试(接口相关); unit 单元测试(函数级别的测试) ![](https://img.kancloud.cn/09/83/09833c0ca0df765a07a6a97dbd22b19e_785x504.png) 执行命令为 创建单元测试命令 > `php artisan make:test 目录` 如下所示 > `php artisan make:test ApiV2/Ad/AdTest ` 命名首字母大写后缀必须以Test结尾 然后方法 必须test开头(下划线风格,或者小驼峰风格) ``` /** * 广告 */ public function testGetAd() { $param=['cate'=>0,'type'=>0]; $ulr='/v1/ad/get_ad'.'?'.http_build_query($param); $response = $this->auth()->get($ulr); $response->assertStatus(200); } ``` 多学一招: > 其中如果以test文件开头的方法,不需要断言可以给方法加上注释 `@doesNotPerformAssertions` 这样就不会提示警告 执行测试文件 > ./vendor/bin/phpunit 或者 php artisan test ./vendor/bin/phpunit --testsuite=Unit 指定执行Unit中的 php artisan test --testsuite=Feature 指定执行Feature中的 需要指定目录或者文件 直接后面接上 如下所示 > ./vendor/bin/phpunit ./tests/Feature/ApiV2/Auth // 只能在 powerShell 窗口,cmd窗口不行 php artisan test ./tests/Feature/ApiV2/Auth // powerShell 窗口,cmd窗口都可以执行并且效果更佳 推荐使用 在windows下面执行 有点讲究 如果用cmd的窗口的则会出现下面尴尬情况 ![](https://img.kancloud.cn/f1/80/f180ce842cb9aac09ba70d4da8ce0740_581x68.png) 这时可用 田键+x 组合键后 会出现 powerShell 窗口的选择既可以使用