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

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
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
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement