> For the complete documentation index, see [llms.txt](https://liseen315.gitbook.io/laravel/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://liseen315.gitbook.io/laravel/qian-duan-zu-jian/ce-shi/ce-shi-message-he-cuo-wu-bao.md).

# 测试Message和错误包

有两种方法测试Message和错误包，首先，您可以在应用程序测试中执行一种行为，该行为设置最终将在某处显示消息，然后重定向到页面断言显示的消息。

其次，对于错误（这是最常见的用例），您可以使用$this->AssertSessionHasErrors($bindings=\[])断言会话的错误。看看示例6-26。

{% code title="Example 6-26. Asserting the session has errors" %}

```php
public function test_missing_email_field_errors() {
    $this->post('person/create', ['name' => 'Japheth']);
    $this->assertSessionHasErrors(['email']);
}
```

{% endcode %}

为了通过示例6-26，您需要向该路由添加输入验证。我们将在第七章讨论这个问题。
