【发布时间】:2020-06-01 16:45:12
【问题描述】:
当我在我的项目上运行 mix test 时,我收到以下错误,我不明白为什么:
$ mix test
Compiling 2 files (.ex)
== Compilation error in file lib/myproject_web/controllers/email_controller_test.ex ==
** (RuntimeError) cannot use ExUnit.Case without starting the ExUnit application, please call ExUnit.start() or explicitly start the :ex_unit app
expanding macro: ExUnit.Case.__using__/1
lib/myproject_web/controllers/email_controller_test.ex:2: MyProjectWeb.EmailControllerTest (module)
(elixir 1.10.1) expanding macro: Kernel.use/2
lib/myproject_web/controllers/email_controller_test.ex:2: MyProjectWeb.EmailControllerTest (module)
我已经在lib/ 中有一个test_helper.exs 文件,它调用ExUnit.start()。我的设置不寻常,因为我希望在模块旁边而不是在单独的 test 文件夹中进行测试。
【问题讨论】:
-
我想分享这些信息,因为它让我彻底疯了。我第一次修复它时我什至不知道如何(我删除并重新制作了一堆文件。)我第二次看到它时,我知道绝望。然后我看到了不一致。
-
当我们运行
mix test时,确保我们位于项目的根目录中很重要。这听起来很基本,但有时我不记得我在项目的子目录中(例如`lib),然后我得到这个错误。
标签: elixir elixir-mix