How to run ExUnit tests within IEx

家住魔仙堡 提交于 2019-12-05 00:44:43

I am assuming you are not using mix. You need to load the test cases to the ExUnit server before running them.

Before Elixir v1.6 you would load the tests like this:

ExUnit.Server.cases_loaded()

And after Elixir v1.6 you would load them like this (thanks to @jeffreymatthias):

ExUnit.Server.modules_loaded()

So the code you should 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.modules_loaded() # Or ExUnit.Server.cases_loaded()

ExUnit.run()

I hope this helps.

According to the ExUnit documentation, ExUnit.run/0 should only be used if you don't want to autostart your tests when you call ExUnit.start/1.

You always have to call ExUnit.start() which would automatically run all the tests unless you pass autorun: false.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!