Ank*_*ngh 2 unit-testing laravel lumen
我正在使用Lumen进行api构建,还想为此编写单元测试用例。但是我面临的问题不是一个有效的断言方法。像assertStatus(),assertNotFound(),assertJson(),等他们全部给错误的调用未定义的方法ExampleTest :: assertMethod() 。以下是我的ExampleTest文件。
<?php
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()
);
}
/** @test */
public function testExample2()
{
$response = $this->get('/');
//getting error here
$response->assertStatus(200);
}
}
Run Code Online (Sandbox Code Playgroud)
我在流明第一次扭动测试用例。请指导我完成此过程。
如果使用Lumen's Laravel\Lumen\Testing\TestCase vs Laravel的default ,则断言的某些方法会有所不同Illuminate\Foundation\Testing\TestCase。
如果要使用assertStatus作为Illuminate\Foundation\Testing\TestCase:
public function testHomePage()
{
$response = $this->get('/');
$response->assertStatus(200);
}
Run Code Online (Sandbox Code Playgroud)
相同的Laravel\Lumen\Testing\TestCase:
public function testHomePage()
{
$response = $this->get('/');
$this->assertEquals(200, $this->response->status());
}
Run Code Online (Sandbox Code Playgroud)