Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log doesn't print when running "mix test"

I'm trying to debug while a test is not running, I have my test and I'm trying to print something so I can see the values of a tuple when mix test is run. I've tried doing this:

require Logger

test "creates element", %{conn: conn} do
    Logger.debug "debugging #{inspect conn}"
    conn = post conn, v1_content_path(conn, :create), content: @valid_attrs
    ...
    ...
end

But nothing is printed! It's driving me nuts! Here is where I read to do what I'm doing How to pretty print conn content?

Edit Also tried with:

IO.puts "debugging #{inspect conn}"

Edit Here the contents of my test_helper.exs

ExUnit.start

Mix.Task.run "ecto.create", ~w(-r TestApp.Repo --quiet)
Mix.Task.run "ecto.migrate", ~w(-r TestApp.Repo --quiet)
Ecto.Adapters.SQL.begin_test_transaction(TestApp.Repo)

Edit Here my whole testing file:

defmodule TestApp.ContentControllerTest do
  require Logger
  use TestApp.ConnCase

  @valid_attrs %{title: "Content Title", url: "http://www.content.com"}
  @invalid_attrs %{}

  setup %{conn: conn} do
    conn
      |> put_req_header("accept", "application/json")

    {:ok, conn: conn}
  end

  test "my first test", %{conn: conn} do
    Logger.debug "debugging #{inspect conn}"
  end
end

Edit Here is the detail of mix test:

$ mix test
.

Finished in 2.5 seconds (0.6s on load, 1.9s on tests)
1 tests, 0 failures

Randomized with seed 685273
like image 266
Martin Perez Avatar asked Mar 31 '16 02:03

Martin Perez


1 Answers

compile_time_purge_level

As pointed out in some comments to your question, the compile_time_purge_level can be reduced to the :debug level for the test environment by changing the :logger config in config/test.exs.

test.exs

config :logger,
  backends: [:console],
  compile_time_purge_level: :debug

run tests again

mix test
like image 85
stephen_m Avatar answered Oct 10 '22 21:10

stephen_m