phpunit在测试应该失败的时候让测试通过


phpunit is letting a test pass when it should fail

我正在关注这个Laracasts视频 https://laracasts.com/lessons/tdd-by-example

在本课中,我们将在 PHPunit 中为store方法创建一个测试SupportController

这是到目前为止的测试。

public function test_submits_support_request_upon_form_submission()
    {
        $this->call('POST', 'support/store', ['name' => 'john']);
    }

我还没有与'support/store'相匹配的溃败.当我运行这个时,我没有得到任何伪造。在视频中,他得到了一个错误Synphoy'Component'HttpKernal'Exeception'NotFoundHttpException

如果测试尝试命中的路由尚不存在,这是有道理的。我正在使用Laravel 5,他在视频中使用了4。我需要更改一些内容才能使其正常工作吗?

当你调用 call 方法时,Laravel 5 完全有可能不会引发异常——即使它与路由不匹配。 如果测试方法未引发异常,并且不包含断言,它将通过。 虽然,也就是说,根据你配置phpunit的方式,它应该警告你你的测试不包含断言。

我会从

  • $this->call('POST', 'support/store', ['name' => 'john']);返回什么?

  • 是否确定您的测试类包含在运行中?

  • 您确定测试运行程序运行您的类吗?

回答这些问题,我怀疑你的问题会出现答案。