Disable Log Output During Tests
·
232 words
·
2 minutes read
It’s quite common to use the log
package within your code to keep track of things which the end user might not need to see, like deprecated notices and warnings. These are great when they are in production and you are monitoring the logs - but they will show up during your tests.
Below is an example test for our example application (even further below) which just asserts that the result of the function is 5. But this same function call also uses log.
To disregard the logs for these tests we use the TestMain
function, set the logging output to discard then run our tests by calling run.
|
|
Our Example Application:
|
|
Screenshot of without and with the discard option: