我试图在测试中使用帮助程序执行任务.我的文件夹结构是这样的:
config/
lib/
test/
test/test_helper.exs
test/provider_test/(the test files are here)
Run Code Online (Sandbox Code Playgroud)
而现在我想做的就是这个
config/
lib/
test/
test/test_helper.exs
test/provider_test/(the test files are here)
test/provider_test/helpers/(the helpers files... more or less, one for helper)
Run Code Online (Sandbox Code Playgroud)
我尝试使用它(在测试中):
HelperModuler.calling_function(args)
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
(UndefinedFunctionError) undefined function HelperModuler.calling_function/1 (module HelperModuler is not available)
Run Code Online (Sandbox Code Playgroud)
Dog*_*ert 10
要在所有测试中使模块可用,您需要做两件事:
.ex.elixirc_paths从中返回的值的键MyApp.Mixfile.project/0中mix.exs.例如,以下是Phoenix如何处理test/support仅在:test混合环境中添加mix.exs:
def project do
[...,
elixirc_paths: elixirc_paths(Mix.env),
...]
end
# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "web", "test/support"]
defp elixirc_paths(_), do: ["lib", "web"]
Run Code Online (Sandbox Code Playgroud)
您还可以在运行时加载代码以Code.require_file在 test.helpers 设置中使用测试。
Code.require_file("test/provider_test/helpers/helper.exs")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1642 次 |
| 最近记录: |