小编Sof*_*per的帖子

预期状态代码 200,但收到 302。无法断言 false 为 true。在 Laravel 5.4 中使用 phpunit 测试

您好,我有这个页面/dno-personal/cebu-properties。我尝试在我的 laravel 中使用 PHPUNIT 测试运行。现在我在下面创建了这个测试文件

<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Http\Response;


class DnoPersonalTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @test
     */
    public function add_cebu_properties_page()
    {


        $response = $this->get('/dno-personal/cebu-properties');
        $response->assertStatus(200);

    }
}
Run Code Online (Sandbox Code Playgroud)

现在,在我的路线文件中,ii 没有为 dno-personal/cebu-properties 创建路线,但我在 phpunit 中运行测试,它会抛出以下错误

Expected status code 200 but received 404.
Failed asserting that false is true.

C:\xampp\htdocs\dnogroup\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:79
C:\xampp\htdocs\dnogroup\tests\Feature\DnoPersonalTest.php:24

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
Run Code Online (Sandbox Code Playgroud)

我认为这是可以的,因为我还没有路线,这会引发 404 错误。现在当我添加到路线中时

Route::get('/dno-personal/cebu-properties',
        'DnoPersonalController@cebuProperties')
        ->name('dno-personal.cebuProperties');
Run Code Online (Sandbox Code Playgroud)

当我运行测试 PHPUNIT 时,我的控制器 …

phpunit laravel-5

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

laravel-5 ×1

phpunit ×1