# Console Tests

You can test what has been output to standard console during Masonite unit tests thanks to useful console assertions.

Output here is the standard output often named `stdout`. Error here is the standard error often named `stderr`.

External packages, prints in your code can output content in console (as output or error).

{% hint style="warning" %}
If you want to assert content output by a Masonite command you should use [Commands Tests](https://docs.masoniteproject.com/development/commands-tests#available-assertions) assertions instead.
{% endhint %}

### Available Assertions

The following assertions are available:

* [assertConsoleEmpty](#assertconsoleempty)
* [assertConsoleNotEmpty](#assertconsolenotempty)
* [assertConsoleExactOutput](#assertconsoleexactoutput)
* [assertConsoleOutputContains](#assertconsoleoutputcontains)
* [assertConsoleOutputMissing](#assertconsoleoutputmissing)
* [assertConsoleHasErrors](#assertconsolehaserrors)
* [assertConsoleExactError](#assertconsoleexacterror)
* [assertConsoleErrorContains](#assertconsoleerrorcontains)

#### assertConsoleEmpty

Assert that nothing has been printed to the console.

#### assertConsoleNotEmpty

Assert that something has been printed to the console (output or error).

#### assertConsoleExactOutput

Assert that console standard output is equal to given output.

```python
print("Success !")
self.assertConsoleExactOutput("Success !\n")
```

#### assertConsoleOutputContains

Assert that console standard output contains given output.

```python
print("Success !")
self.assertConsoleOutputContains("Success")
```

#### assertConsoleOutputMissing

Assert that console standard output does not contain the given output.

```python
print("Success !")
self.assertConsoleOutputMissing("hello")
```

#### assertConsoleHasErrors

Assert that something has been output to console standard error.

#### assertConsoleExactError

Assert that console standard error is equal to given error.

```python
print("An error occured !", file=sys.stderr)
self.assertConsoleExactError("An error occured !\n")
```

#### assertConsoleErrorContains

Assert that console standard error contains given error.

```python
print("An error occured !", file=sys.stderr)
self.assertConsoleErrorContains("error")
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.masoniteproject.com/development/testing/console-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
