Laravel 预期状态码 200 但收到 500

时间:2021-02-22 15:12:08

标签: php laravel laravel-5 phpunit tdd

这是我的单元测试的代码,默认的:

<?php

namespace Tests\Feature;

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

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
}

我正在运行 Laravel 项目:php artisan serv

当我手动访问 / 时,项目工作正常!但是在测试中我收到此错误:

  Expected status code 200 but received 500.
  Failed asserting that 200 is identical to 500.

这是完整的输出:

  FAIL  Tests\Feature\ExampleTest
  ⨯ basic test

  ---

  • Tests\Feature\ExampleTest > basic test
  Expected status code 200 but received 500.
  Failed asserting that 200 is identical to 500.

  at tests/Feature/ExampleTest.php:19
     15▕     public function testBasicTest()
     16▕     {
     17▕         $response = $this->get('/');
     18▕ 
  ➜  19▕         $response->assertStatus(200);
     20▕     }
     21▕ }
     22▕

请问我该如何解决?

1 个答案:

答案 0 :(得分:0)

在调用 self.bumpiness() 之前,插入对 $this->get() 的调用。它将显示错误的详细信息。

相关问题