Speeding up tests by pre-compiling them

Not really sure if this is a question or suggestion, but in an attempt to speed up our tests, we switched to .ex files and have them compiled by default using mix. When Mix.env == :test, elixirc_paths pretty much looks like:

defp paths(:test) do
  # need to start this here since compilation of a ExUnit.Case causes the
  # module to be registered in ExUnit.Server (via an after_compile hook)
  paths(:prod) ++ ["test"]

Instead of building the built-in mix test task, we have our own simplified that a) is able to leverage the already-compiled modules and b) maintains some of the basic functionality we needed (like cover, and being able to run specific path/file with optional line number.

Depending on the computer, this shaves 5-20 seconds off running our tests. It can be slower for single runs in specific conditions (like touching a lot of tests, but only running 1), but even this is faster when you eventually run those other touched tests.

What would make this much better is if this was simply a flag that can be passed to mix test.

Am I the only one that finds the startup time of mix test to be prohibitive?


I am starting a real project with Elixir and the test suite is very samall but the startup time already annoys me… So you are not the only one :wink:

1 Like

There is now an issue for this Allow test files to be compiled · Issue #10983 · elixir-lang/elixir · GitHub