laravel中集成了单元测试工具phpunit可以在项目的根目录下进行使用,命令是:phpunti ./tests/单元测试文件名称。在phpstorm中使用phpunit需要做一些配置,指定composer的autoload.php就可以了。具体做法如下:
1、选择File->Setting->Languages&Framework->php->phpunit;
2、在phpunit liberay中选择 Use Composer autoloader;
3、在下面的框中填写项目目录/vendor/autoload.php;
保存之后就完成了配置。
配置完毕后 ,右键 要单元测试的文件即可,
例如单元测试文件可以这么写:
<?php use Laravel\Lumen\Testing\DatabaseTransactions; class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
$this->get('/'); $this->assertEquals(
$this->app->version(), $this->response->getContent()
);
} public function testInsert(){
$this->get('/user/getlist');
$data=$this->response->getContent();
var_dump($data);
$this->assertTrue(strpos($data,'{')!==false);
} }