[笔记]Laravel TDD 胡乱记录

TDD: 测试驱动开发(Test-Driven Development),TDD的原理是在开发功能代码之前,先编写单元测试用例代码,测试代码确定需要编写什么产品代码。 -- 载自TDD百度百科

参考 Test Driven API Development using Laravel, Dingo and JWT with Documentation

  1. 更正运行命令:
php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"
  1. 运行文章第二步进行单元测试命令,提示 Illuminate\Database\QueryException: could not find driver (SQL: select * from sqlite_master where type = 'table' and name = migrations)的错误信息,在php artisan migrate gives me an error could not find driver 找到解决方法,在 ubuntu中运行 sudo apt-get install php-sqlite3.

  2. laravel项目不是运行在根目录下,修复直接访问 http://localhost/blog/public/api时,会 301 重定向到 http://localhost/api下, 修改 .htaccess 文件中的RewriteRule ^(.*)/$ /$1 [L,R=301]RewriteRule ^(.*)/$ public/$1 [L,R=301], 参考链接: Removing "/public" from URL (Where does Laravel get the base URL from?)

  3. phpunit testunits 说明 phpunit 单元测试--laravel[持续更新]

    测试类中的所有方法必须为public 修饰并且以test开头的public function test*(){}方式

  4. 更正 文章中的命令 phpunit tests/FruitsTest.phpphpunit tests/Feature/FruitsTest.php,测试类中的方法名必须加上 test开发,如文章中的it_fetches_fruits 得改为 testit_fetches_fruits,运行测试的时候,才会运行这个方法

  5. laravel连接sqlite Connect to an Sqlite DB - Laravel documentation procedure doesn't work

  6. 备份Laravel .env 文件中mysql 配置信息

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

目前使用Laravel大多数是写api, 我的单个测试用例是判断返回结果的HTTP状态码(是最简单,但是准确性不是很高,至少在整个单元测试跑下来之后全绿,自己的心里对已写的程序还是比没有任何单元测试的时候踏实了些)

猜你喜欢

转载自www.cnblogs.com/fsong/p/11259185.html
TDD
今日推荐