Noise in ExUnit results when using assert_raise

I wrote a test like this:

test "Exception should be raised" do
  assert_raise MyApp.CustomException, fn -> MyApp.do_something("invalid data") end
end

It passes, but I notice in the terminal when I do a full test pass, I see a red error message after all the dots, e.g. ......................................12:36:48.407 [error] My custom message here

Am I using assert_raise correctly? Why is that message showing up in the logs?

Thanks for any pointers!

It looks like you’re using assert_raise correctly here. My guess is that you’re logging that error from somewhere inside your function. If that is true then you can use capture_log to prevent the log from being printed out (and optionally assert on the log contents): https://hexdocs.pm/ex_unit/ExUnit.CaptureLog.html

4 Likes