这是我的单元测试的代码,默认的:
<?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▕
请问我该如何解决?
答案 0 :(得分:0)
在调用 self.bumpiness()
之前,插入对 $this->get()
的调用。它将显示错误的详细信息。