【问题标题】:Error 500 when exectuting basic phpunit test on laravel在 laravel 上执行基本 phpunit 测试时出现错误 500
【发布时间】:2021-05-16 01:59:12
【问题描述】:

我有一个使用 Vagrant Homestead 在本地网络上运行的 Laravel 应用程序。 我尝试实现 HTTP 测试,我首先创建了一个像文档这样的基本测试:

/**
 * A basic feature test example.
 *
 * @return void
 */
public function testExample()
{
    $response = $this->get('/');

    $response->assertStatus(200);
}

但是当我运行测试时,我收到了错误: 预期的状态代码为 200,但收到了 500。

但是我可以毫无问题地访问我的网站。

我做错了什么?

谢谢

【问题讨论】:

  • 使用$this->withoutExceptionHandling();查看实际异常。
  • @leoden 你能分享文件Test Case的所有内容吗?
  • @apokryfos 谢谢你,我现在有我的例外:ErrorException : Route [category.show] not defined. (View: homepage.blade.php) 我可以调试它。问题是我用语言环境重命名了我的路线,例如: fr.category.showen.category.show

标签: laravel http testing phpunit


【解决方案1】:

@ThânLƯƠNG 是的,这是自动生成的测试用例:


namespace Tests\Feature;

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

class BasicTest extends TestCase
{

    /**
     * A basic feature test example.
     *
     * @return void
     */
    public function testExample()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }

}

【讨论】:

    猜你喜欢
    • 2015-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-18
    • 2020-12-09
    • 2014-05-08
    • 1970-01-01
    • 2013-07-17
    相关资源
    最近更新 更多