当 运行 `mix tests` 但不在控制台中时,函数 A.B.c/1 未定义或私有

function A.B.c/1 is undefined or private when running `mix tests` but not in console

这个问题的后续问题

我大致遇到了同样的问题。函数被认为是未定义的或私有的。

上面link中的解决方案有效!在 $ iex -S mix phx.server I 运行 recompile() 中,函数不再是未定义或私有的。

我的问题是它在我的测试套件中仍然是未定义的或私有的。 当我 运行 mix tests 时,我又得到了 UndefinedFunctionError

我运行从项目的根目录进行测试。

测试模块缺少 Test 后缀的名称。换句话说,被测试的模块被称为 MyApp.MyModule,进行测试的模块也是如此。

如果要测试的模块名为MyApp.MyModule,测试应该在 MyApp.MyModuleTest