TDD: 测试驱动开发(Test-Driven Development),TDD的原理是在开发功能代码以前,先编写单元测试用例代码,测试代码肯定须要编写什么产品代码。 -- 载自TDD百度百科php
参考 Test Driven API Development using Laravel, Dingo and JWT with Documentationhtml
php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"
运行文章第二步进行单元测试命令,提示 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
.mysql
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?)laravel
phpunit testunits 说明 phpunit 单元测试--laravel[持续更新]sql
测试类中的全部方法必须为public 修饰而且以test开头的public function test*(){}方式ubuntu
更正 文章中的命令 phpunit tests/FruitsTest.php
为phpunit tests/Feature/FruitsTest.php
,测试类中的方法名必须加上 test开发,如文章中的it_fetches_fruits
得改成 testit_fetches_fruits
,运行测试的时候,才会运行这个方法api
laravel链接sqlite Connect to an Sqlite DB - Laravel documentation procedure doesn't workide
备份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状态码(是最简单,可是准确性不是很高,至少在整个单元测试跑下来以后全绿,本身的内心对已写的程序仍是比没有任何单元测试的时候踏实了些)测试