ExUnit starts your applications automatically

Hey All,

I had a quick question regarding ExUnit - it appears to start your application by default which is a different behaviour to EUnit.

I was wondering if there is a way to tell ExUnit to not start the application when running mix test, I’d like to control the start/stop of the application inside the test itself for various reasons.

Also is there a reason for this behaviour difference between ExUnit and EUnit?

Thanks for the help!

/Howard

1 Like

Use --no-start option as described here:

https://github.com/elixir-lang/elixir/blob/master/lib/mix/lib/mix/tasks/test.ex#L56

The reason is probably convenience. Most people want to start the app for the tests, I think, so that’s the default.

Thanks for the reply :slight_smile:,

I disagree a little with elixir doing this for unit tests as in most cases it’s a bit of an unnecessary overhead and sometimes in your Jenkins/GitLab/Travis test environment it’s not even possible to start all included applications.

EUnit tests are supposed to be lightweight, white-box function-by-function tests. ExUnit seems to be blurring the line between EUnit and CT, which may be the intention and I could just be stuck in my erlang ways.

But as you quite rightly pointed out the answer was staring me in the face in the documentation :stuck_out_tongue:.

1 Like

funny enough, I just wanted to do the same thing. So I can give you better, albeit late answer.

In order to avoid writing mix test --no-test in command line, you can define an alias in your mix.exs file like this:

def project do
  [app: :core,
   ...
   aliases: [test: "test --no-start"],
   ...
   deps: deps()]
end

This way, whenever you run mix tests it will skip the starting application. Here’s a blog post I found on the subject that gives couple more extra tips:

https://virviil.github.io/2016/10/26/Elixir-Testing-without-starting-supervision-tree.html

3 Likes

The link to Virvill’s blog is dead now, but it is still available on the Internet Archive Wayback Machine

2 Likes