Is there a way to check if a function has been called from a ExUnit test case? I have a function that calls IO.puts and I would like to test and verify that something is being outputted to STDOUT via a test case.
I saw this: http://erlang.org/pipermail/erlang-questions/2005-July/016259.html. But I was hoping there might be a simpler way of doing this with ExUnit.
Is there a way to check and see if my function calls IO.puts? Or at least check and see if something has been sent to STDOUT?
If you just want to test the STDOUT via a test case, I think CaptureIO can be used. The following has the spec and sample code.
https://hexdocs.pm/ex_unit/master/ExUnit.CaptureIO.html
You could mock the method calls using some mocking libraries, but for STDOUT, the above one would be simpler approach.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments