Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I still print logs to console while running ExUnit tests?

Tags:

elixir

ex-unit

For debugging purposes during a failing integration test, I would like to still be able to see my application logs. Is there a command I can pass to the mix test task to accomplish this?

like image 608
o_o_o-- Avatar asked Jul 26 '16 00:07

o_o_o--


1 Answers

Every mix project has a config.exs file. When mix starts, it loads this file. A common pattern in elixir is to define configs for different environments, like test.exs, dev.exs, prod.exs, etc, etc.

Many projects like Phoenix will generate these files for you in your config folder, and you'll see this line in your config.exs line:

import_config "#{Mix.env}.exs"

When you run mix test it sets MIX_ENV environment variable to "test" which means the import_config line loads your test.exs file.

So in order to set your logging level for just your tests, in your test.exs file you can write the following:

# Print only warnings and errors during test
config :logger, level: :warn
like image 199
rozap Avatar answered Nov 20 '22 19:11

rozap