I am trying to figure out how to test my project and I was going to try to make Fakes for the edges of my system. In my case that is the network, a udp socket. To do that, I was going to start up a GenServer to manage the "faked" open connections. I can't seem to make a test only application and add it without mix getting mad. Given this application I defined in test/support
defmodule MyProjectTest.Application do
use Application
def start(_type, _args) do
children = [
GenUdpFake,
]
opts = [strategy: :one_for_one, name: MyProjectTest.Supervisor]
Supervisor.start_link(children, opts)
end
end
I tried to use the following in my mix.exs
def application do
[
mod: {MyProject.Application, []},
extra_applications: [:logger, :runtime_tools] ++ extra_applications(Mix.env())
]
end
defp extra_applications(:test) do
[MyProjectTest.Application]
end
defp extra_applications(_) do
[]
end
I always get the following error running mix test.
** (Mix) Could not start application Elixir.MyProjectTest.Application: could not find application file: Elixir.MyProjectTest.Application.app
However, I even went into the build folder and found _build/test/lib/my_project/ebin/Elixir.MyProjectTest.Application.beam. I even found it in my_project.app under the modules, but not the applications. So, I am supper confused what I am doing wrong. I can't seem to find any info about adding an application that isn't from dependencies to the extra_application: property. The mix documentation doesn't really tell me much more. The application documentation doesn't really say anything. I am pretty sure all I want is 'Elixir.MyProjectTest.Application' to be included in the applications section of my_project.app. Is this something I am not allowed to do? If not, what am I missing?
I think the issue is that although the module is called Application, it's not a beam application.
You probably want to list it in the
childrenof your test supervision tree, rather than theextra_applications. Or skip the extra application module completely, and putGenUdpFakein thechildren.Another option is to start the fake in your test setup, with