Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure applications to be loaded only in test environment

How can I configure applications to be loaded in run time only in a certain environment? I know I can configure a dependency only for test environment.
Is there a way to configure applications in mix.exs to be loaded only in test environment?
For example:

  def application do
    [mod: {MyApp, []},
     applications: [:phoenix]]   end

  defp deps do
    [{:phoenix, "~> 1.2.1"}] end

Can I configure phoenix application only for test environment?

like image 885
faigy langsam Avatar asked Dec 13 '25 13:12

faigy langsam


1 Answers

As @JustinWood stated in the comments, if you're using elixir 1.4, you can use application inference to do this automatically for you.

If you have to use a version of elixir before 1.4, the way to do this would be to have something similar to the following in your mix.exs:

def application do
  [
    mod: {MyApp, []},
    applications: applications(Mix.env)
  ]
end

defp applications(:test), do: applications(:default) ++ [:test_only_app_1, :test_only_app_2]
defp applications(_),     do: [:logger, :httpoison]
like image 160
Navin Peiris Avatar answered Dec 16 '25 00:12

Navin Peiris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!