If this is just a matter of a single helper, put it into your test/test_helper.exs
.
But as the project grows, it becomes harder to manage. The common approach is to create test/support
folder, and modify your mix.exs
in the following way:
- Create a private function like this:
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
- Modify your
Mix.Project.project/0
callback to include the following key/value pair:
elixirc_paths: elixirc_paths(Mix.env())
- Put all the files containing modules needed in
test
environment only there, as *.ex
files.
That way all of them will be compiled in test
and discarded in all other environments.