hazardfn

hazardfn

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

First Post!

hubertlepicki

hubertlepicki

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.

Most Liked

hubertlepicki

hubertlepicki

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

KronicDeth

KronicDeth

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

hazardfn

hazardfn

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:.

Where Next?

Trending in Questions Top

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
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
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
tj0
I’ve been following the steps here for the upgrade from 1.6 to 1.7 and it has gone relatively smoothly all the way till the phoenix_view ...
New
cgraham
Hi! What is currently the best library/method for parsing text and tabular data out of PDF files in Elixir or Erlang?
New
stefanchrobot
Hi, I need a way to handle data migrations in my application. I found an article by @wojtekmach about manual migrations: Automatic and ma...
New
stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
webofbits
Squid Mesh is an open source workflow automation runtime for Elixir applications. It is aimed at Phoenix and OTP apps that want to defin...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New

We're in Beta

About us Mission Statement