马会东的博客

马会东的博客

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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);
    }

}

 

posted on 2016-11-30 19:28  马会东  阅读(1738)  评论(0编辑  收藏  举报