user626511
user626511

Reputation:

Elixir ExUnit: module under test is not available

I'm following this tutorial: http://elixir-lang.org/getting-started/mix-otp/agent.html

So in my Elixir project I have a module lib/kv/bucket.exs, and a test for it test/kv/bucket_test.exs.

When I'm running mix test, I get the following error: ** (UndefinedFunctionError) undefined function KV.Bucket.start_link/0 (module KV.Bucket is not available) Am I missing something?

Upvotes: 14

Views: 3065

Answers (2)

towry
towry

Reputation: 4286

See https://hexdocs.pm/mix/1.14/Mix.Tasks.Compile.Elixir.html#module-configuration

:elixirc_paths - directories to find source files. Defaults to ["lib"].

So we define the :elixirc_paths in test env to load ["lib", "test/support"], and in test/support, put your mock .ex files here, then the test files are able to find the test mock modules.

Upvotes: 0

user626511
user626511

Reputation:

So it turns out, the module has to use an .ex extension instead of .exs, and you need to run mix compile to compile the new module. After that, mix test is able to find the module and everything works as expected.

Upvotes: 17

Related Questions