bokner

bokner

Running ExUnit tests from iex shell

Hello everyone,

I’m trying to run ExUnit tests from the shell, and I almost got it working:

iex(2)> ExUnit.start(autorun: false)                                                                            
:ok
iex(3)> test_file = "test/sample_test.exs"
"test/sample_test.exs"
iex(4)> Mix.Compilers.Test.require_and_run([test_file], ["test"], formatters: [ExUnit.CLIFormatter])

........

Finished in 3.6 seconds
8 tests, 0 failures
{:ok, %{excluded: 0, failures: 0, skipped: 0, total: 8}}

So far so good, but the second run of Mix.Compilers.Test.require_and_run/3 doesn’t seem to do anything:

iex(5)> Mix.Compilers.Test.require_and_run([test_file], ["test"], formatters: [ExUnit.CLIFormatter])

Finished in 0.00 seconds
0 failures

{:ok, %{excluded: 0, failures: 0, skipped: 0, total: 0}}

It looks like the test compiler caches the test results. If that’s the case, can it be forced to invalidate it and run the tests from scratch again?

Most Liked

paulanthonywilson

paulanthonywilson

I wanted to do this because of the apps I’m working in at the moment has a long startup time, making TDD painful. Someone pointed me to a solution based on TestIex — Easier Test Driven Development in Elixir | by Daniel Olshansky | Medium and it works like treat.

filipe

filipe

basically you have to load it again to rerun the test

Code.load_file(test_file)

or even better compile_file, since load_file is depricated

Code.compile_file(test_file")

then you can rerun

Mix.Compilers.Test.require_and_run([test_file], ["test"], formatters: [ExUnit.CLIFormatter])

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement