Masonite Documentation
v4.0
v4.0
  • Introduction and Installation
  • Prologue
    • Creating A Blog Tutorial
    • Release Cycle
    • Contributing Guide
    • How To Contribute
  • The Basics
    • Routing
    • Controllers
    • Middleware
    • Response
    • Request
    • Static Files
    • Views
    • Environments
    • Configuration
    • Error Handling
  • Features
    • API Development
    • Authentication
    • Authorization
    • Broadcasting
    • Caching
    • Compiling Assets
    • Commands
    • CSRF Protection
    • Events
    • Facades
    • Filesystem and Uploading
    • Hash ID's
    • Helpers
    • Mail
    • Notifications
    • Package Development
    • Queues and Jobs
    • Rate Limiting
    • Sessions
    • Task Scheduling
    • Tinker Shell (REPL)
    • Validation
  • Architecture
    • Service Providers
    • Service Container
  • Security
    • CORS
    • Hashing
  • Masonite ORM
    • To Masonite ORM Docs
  • Testing
    • Getting Started
    • HTTP Tests
    • Database Tests
    • Commands Tests
    • Console Tests
    • Mocking
    • Extending
  • Official Packages
    • Masonite Debugbar
  • How-to Guides
    • Handling AJAX requests with expired authentication
    • Build Email Verification from Scratch With Masonite Framework and JSON Web Tokens
    • Deploying a Masonite Application to Heroku
    • How To Deploy Masonite to PythonAnywhere
    • How-To: Use RabbitMQ with Masonite 2.0 queues
    • How To Use The Repository Pattern with Masonite
    • Making Masonite and Laravel Mix work together
  • What's New
    • Masonite 1.3
    • Masonite 1.4
    • Masonite 1.5
    • Masonite 1.6
    • Masonite 2.0
    • Masonite 2.1
    • Masonite 2.2
    • Masonite 2.3
    • Masonite 3.0
  • Upgrade Guide
    • Masonite 1.3 to 1.4
    • Masonite 1.4 to 1.5
    • Masonite 1.5 to 1.6
    • Masonite 1.6 to 2.0
    • Masonite 2.0 to 2.1
    • Masonite 2.1 to 2.2
    • Masonite 2.2 to 2.3
    • Masonite 2.3 to 3.0
    • Masonite 3.0 to 4.0
Powered by GitBook
On this page
Edit on GitHub
Export as PDF
  1. Testing

Console Tests

PreviousCommands TestsNextMocking

Last updated 3 years ago

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).

If you want to assert content output by a Masonite command you should use assertions instead.

Available Assertions

The following assertions are available:

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.

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

assertConsoleOutputContains

Assert that console standard output contains given output.

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

assertConsoleOutputMissing

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

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.

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

assertConsoleErrorContains

Assert that console standard error contains given error.

print("An error occured !", file=sys.stderr)
self.assertConsoleErrorContains("error")
assertConsoleEmpty
assertConsoleNotEmpty
assertConsoleExactOutput
assertConsoleOutputContains
assertConsoleOutputMissing
assertConsoleHasErrors
assertConsoleExactError
assertConsoleErrorContains
Commands Tests