测试命令行输出
这是一篇协同翻译的文章,你可以点击『我来翻译』按钮来参与翻译。
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).
注意:If you want to assert content output by a Masonite command you should use Commands Tests assertions instead.
Available Assertions
The following assertions are available:
- assertConsoleEmpty
- assertConsoleNotEmpty
- assertConsoleExactOutput
- assertConsoleOutputContains
- assertConsoleOutputMissing
- assertConsoleHasErrors
- assertConsoleExactError
- 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.
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")
本文中的所有译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接
我们的翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。