How to run ExUnit tests in IEx

I am trying to run IEx.pry in a test. However, I cannot run the tests as part of an iex session. Please note that I am not using a mix.

 ExUnit.start defmodule Calc do def add(a,b) do a + b end end defmodule TheTest do use ExUnit.Case test "adds two numbers" do require IEx IEx.pry assert Calc.add(1, 2) == 3 end end 

I try to start it using ExUnit.run freezes and eventually shuts down:

 manuel@laptop :~/exercism/elixir/nucleotide-count$ iex test.exs Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false] Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> ExUnit.run ** (exit) exited in: GenServer.call(ExUnit.Server, {:take_async_cases, 8}, 60000) ** (EXIT) time out (elixir) lib/gen_server.ex:604: GenServer.call/3 (ex_unit) lib/ex_unit/runner.ex:71: ExUnit.Runner.loop/2 (stdlib) timer.erl:166: :timer.tc/1 (ex_unit) lib/ex_unit/runner.ex:13: ExUnit.Runner.run/2 

The code is loaded correctly, and I can directly call it with TheTest."test adds two numbers"({}) . But I was hoping to do this by releasing the whole package.

+5
source share
2 answers

I assume you are not using mix . You need to upload test cases to the ExUnit server before starting them with:

 ExUnit.Server.cases_loaded() 

So, the code you have to write in iex should be:

 ExUnit.start() defmodule Calc do def add(a,b) do a + b end end defmodule TheTest do use ExUnit.Case test "adds two numbers" do require IEx IEx.pry() assert Calc.add(1, 2) == 3 end end ExUnit.Server.cases_loaded() ExUnit.run() 

Hope this helps.

+4
source

According to the ExUnit Documentation , ExUnit.run/0 should be used only if you do not want the tests to run automatically when ExUnit.start/1 called.

You always need to call ExUnit.start() , which automatically runs all the tests if you fail autorun: false .

0
source

Source: https://habr.com/ru/post/1260354/


All Articles