문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top