Best way to quickly test run an .exs file

I can think of a way to quickly test a few functions I wrote by writing an .exs file and then running it with mix run path/to/file.exs to get output in terminal.

I am not using tests (TDD) because the functions will fetch some http response and I need them in terminal to understand them. (and accordingly process it later)

  1. What are other good ways to quickly test small functions to see their output in terminal?
  2. lacunae of above approach.
  3. Anything else you want to suggest.

i too am a new Elixir programmer and here is what i do:

Write your function and all that function as explained below

defmodule Example do
  def add_numbers(num1, num2) do
    num1 + num2
    |> inspect
    |> IO.puts 
  end
end
Example.add_numbers(2, 3)

Save the file with .exs and to run/test use command from a command shell
elixir FILENAME.exs

Hope this helps

3 Likes

Also, you can just alias the module directly into iex and call this function directly there. You don’t need to create another file just to run this manually.

You can also take a look at this require IEx; IEx.pry to understand how is your function behaving at every step. or you can use IO.inspect().

1 Like

thanks for the awesome information.