【问题标题】:Laravel 5 | PHPUnit Testing ErrorLaravel 5 | PHPUnit 测试错误
【发布时间】:2016-06-04 18:56:44
【问题描述】:

我只想获取链接的状态码(路径)。

[我也使用 Auth]

我的输入:

public function testPath()
{
    $this->withoutMiddleware();
    $this->call('GET', '/admin/create');
    $this->assertResponseStatus(200);
}

即使我在浏览器上检查了这个,我也得到了正确的响应。 但是在 PHPUnit 测试中,我得到以下错误...

1) ItemsTest::testPath
   Expected status code 200, got 500.
   Failed asserting that 500 matches expected 200

我的测试代码有什么问题...?

【问题讨论】:

  • 尝试$this->visit('/admin/create'); 而不是$this->call('GET', '/admin/create');
  • K...那我怎么检查它的状态码....
  • $cont = $this->visit('/admin/create'); $cont->assertResponseOk();我得到同样的错误......
  • 你设置好路线了吗?
  • 是的......我解决了......问题是由验证错误变量发生......

标签: unit-testing laravel testing phpunit laravel-5.2


【解决方案1】:

终于找到了解决办法。

实际上我的视图文件有一些验证错误。

验证 $errors 变量最初未定义,因此在 PHPUnit 测试用例中将此视为错误。

所以它为我返回 500 内部服务器错误...

【讨论】:

    猜你喜欢
    • 2016-07-28
    • 2015-10-14
    • 2016-05-21
    • 1970-01-01
    • 2017-11-29
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多