Laravel 5.8上的PHPUnit测试失败

时间:2019-08-09 10:24:12

标签: php laravel unit-testing

我正在laravel 5.8项目中工作。

127.0.0.1/test_project/public/index.php.

我收到404响应。我该如何解决?

我有一个测试:

路线:

Route::apiResource('Vehicle.source', 'API\VehicleController');

API调用:

http://127.0.0.1/test_project/public/index.php/api/Vehicle/22222/source/DB

API Response:
{
    "data": [
        {
            "id": 1,
            "identifier": "22222",
            "make": "wwwww",
            "model": "3333",
            "year": 44445,
            "created_at": "2019-08-02 07:02:51",
            "updated_at": "2019-08-02 07:02:51"
        },
        {
            "id": 2,
            "identifier": "22222",
            "make": "wwwww",
            "model": "3333",
            "year": 44445,
            "created_at": "2019-08-02 07:21:01",
            "updated_at": "2019-08-02 07:21:01"
        }
    ],
    "status": 500
}

<?php
namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class VehicleTest extends TestCase
{
    public function testGetVehicleFromDB() 
    {
        $response = $this->json('GET', '/api/Vehicle/22222/DB');  
        $response->assertStatus(200);
        $response->assertJson(['message' => "Vehicle Retrived!"]);
    }
}
?>

错误消息如下:

  

1)Tests \ Unit \ VehicleTest :: testGetVehicleFromDB预期状态代码   200,但收到404。断言false为真失败。

     

C:\ xampp \ htdocs \ fixico_test \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Testing \ TestResponse.php:151   C:\ xampp \ htdocs \ fixico_test \ tests \ Unit \ VehicleTest.php:25

     

失败!测试:3,断言:3,失败:1。

0 个答案:

没有答案