Skip to content

Latest commit

 

History

History
63 lines (47 loc) · 805 Bytes

ex_unit_rerun_demo.livemd

File metadata and controls

63 lines (47 loc) · 805 Bytes

ExUnit Rerun Demo

Test Case

ExUnit.start()

defmodule SampleTest do
  use ExUnit.Case

  test "it pass" do
    assert MyMath.add(2, 2) == 4
  end

  test "it fails" do
    refute MyMath.add(2, 2) == 5
  end
end

ExUnit.run()

Implementation

defmodule MyMath do
  def add(a, b) do
    a + b
  end
end

ExUnit.run()

Hack

test_content =
  quote do
    use ExUnit.Case

    test "it pass" do
      assert MyMath.add(2, 2) == 4
    end

    test "it fails" do
      refute MyMath.add(2, 2) == 5
    end
  end

Module.create(SampleTest, test_content, Macro.Env.location(__ENV__))
ExUnit.run()

defmodule MyMath do
  def add(a, b) do
    # wrong impl
    a - b
  end
end

Module.create(SampleTest, test_content, Macro.Env.location(__ENV__))
ExUnit.run()