[英]Laravel Expected status code 200 but received 500
這是我的單元測試的代碼,默認的:
<?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.
這是完整的 output:
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▕
請問我該如何解決?
在$this->get()
調用之前,插入對$this->withoutExceptionHandling()
的調用。 它將向您顯示錯誤的詳細信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.