我试图在测试中使用帮助程序来执行任务。我的文件夹结构如下:
config/
lib/
test/
test/test_helper.exs
test/provider_test/(the test files are here)
现在我要做的就是这个
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)
我尝试使用它(在测试中):
HelperModuler.calling_function(args)
但是我收到了这个错误:
(UndefinedFunctionError) undefined function HelperModuler.calling_function/1 (module HelperModuler is not available)
答案 0 :(得分:10)
要在所有测试中使模块可用,您需要做两件事:
.ex
。elixirc_paths
中MyApp.Mixfile.project/0
返回值的mix.exs
键。例如,以下是凤凰城处理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"]
答案 1 :(得分:4)
您还可以在test.helpers设置中使用 Code.require_file("test/provider_test/helpers/helper.exs")
在运行时加载代码以进行测试。
$scope.pickFile = function() {
filepicker.setKey("...");
filepicker.pick(
{},
function(Blob) { // OnSuccess
var uuid = Blob.url.split('/').slice(-1)[0];
window.location.replace("/url" + uuid);
$.post(
"/other_url" + uuid,
{'input': $('#rawText')[0].checked? "text" : "features"}
);
});
}
答案 2 :(得分:1)
def project do
[app: :example,
version: "0.1.0",
elixir: "~> 1.4",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
elixirc_paths: ["lib", "path_to_your_src"],
deps: deps()]
end
将此行elixirc_paths: ["lib", "path_to_your_src"],
添加到project
mix.exs
函数的返回内容