How to run ExUnit tests within IEx

前端 未结 3 1294
轻奢々
轻奢々 2021-02-20 00:49

I\'m trying to launch IEx.pry within a test. However I cannot get to run the tests within an iex session. Note that I\'m not using mix.

ExUnit.start         


        
相关标签:
3条回答
  • 2021-02-20 00:59
    alias ExUnit.Assertions
    require Assertions
    Assertions.assert 1==1
    true
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-20 01:22

    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.

    0 讨论(0)
提交回复
热议问题