Lumen开发:phpunit单元测试

先来直接运行,cmd先进入根目录,然后进入tests或是test文件夹

运行命令行:..\vendor\bin\phpunit ExampleTest.php

laravel/lumen中集成了PHPUnit, 测试的配置文件为根目录下的phpunit.xml,该配置文件为我们做好了所有配置工作。

use Laravel\Lumen\Testing\DatabaseMigrations;
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()//判断访问结果与期望值是否一致
        );
    }
}

可参考:

http://laravelacademy.org/post/2232.html

https://docs.golaravel.com/docs/4.0/testing/

http://www.cnblogs.com/pengzhendong/p/5017557.html

 

解决

'..\vendor\bin\phpunit' 不是内部或外部命令,也不是可运行的程序或批处理文件。

进入\vendor\bin 运行 phpunit ../../tests/XXXTest.php

 

相关:https://laravel-china.org/docs/lumen/5.3/testing/1895

posted @ 2017-09-18 18:48  程序生(Codey)  阅读(1328)  评论(0编辑  收藏  举报