erlang - 原因: undef while running common tests in erl console [Erlang]

标签 erlang erlang-shell common-test

我正在运行应用程序,并且在交互式控制台中我尝试运行位于 test/common 目录中的通用测试套件:

ct:run("test/common").

但是我收到了一堆错误:

Reason: undef

并且所有测试都失败。 我尝试从 linux shell 运行它们

ct_run -dir test/common

或者像这样:

ct_run -boot start_sasl -spec test/common/app_ct.spec -erl_args -config env/dev.config

结果相同。

但是当我使用 rebar(第二个版本,而不是 rebar3)运行它们时

rebar ct

一切正常,测试通过。但编译和启动应用程序需要太多时间。

在 rebar.config 中我有:

{ct_dir,"test/common"}.
{ct_log_dir,"test/logs"}.
{ct_extra_params,"-boot start_sasl -pa deps/*/ebin -pa ebin -spec test/common/app_ct.spec -erl_args -config env/dev.config"}.

在 test/common/app_ct.spec 中我有:

{verbosity, 100}.
{init, {eval, [{application, ensure_all_started, [app]}, {timer, sleep, [30000]}]}}.
{alias, common, "./test/common/"}.
{suites, "", [app_srv_SUITE, app_client_SUITE]}.

如何使用 ct:run("test/common") 从 erl 控制台运行测试?

我的目标是能够单独重新编译单个测试文件并从工作应用程序控制台运行测试,而无需停止和重新编译所有应用程序。

我重新编译单一测试模块,没有出现这样的问题:

c("test/common/new_mod_SUITE.erl", [{i, "include"}, {i, "deps"}, {outdir, "test/common"}]). 

但之后我仍然无法运行测试。

最佳答案

首先,需要确保所有测试都已编译,并且它们位于作为参数放入 ct:run/1 的文件夹内。 。如果只需要从特定文件夹运行一个测试,可以使用ct:run/2 。如果需要从特定文件夹运行特定测试用例,可以使用特定文件夹 ct:run/3 。示例:

1> ct:run("test/common").
2> ct:run("test/common", "some_SUITE").

但是我建议使用 rebar3 ,在 rebar3 中添加了 --dir 等选项,并且可以运行来自特定文件夹的测试,如下所示:

$ ./rebar3 ct --dir="test/common"

关于erlang - 原因: undef while running common tests in erl console [Erlang],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66163734/

相关文章:

使用relx时erlang dbg模块不工作

Erlang 异步消息处理与 gen_server :cast/2

erlang - 常见测试中如何测试错误处理?

erlang - 如何导出所有函数仅用于普通测试?

bash - 通过 Erlang 端口调用时,Shell 脚本表现异常

multithreading - Erlang 进程如何(如果有的话)映射到内核线程?

erlang - 将 map 转换为erlang中的列表的函数

erlang - 如何在 Erlang 中检查列表是否为空?

erlang - 为什么可以在 Erlang 中创建对同一进程的多个监视器引用?

erlang - 如何为 Erlang/OTP 构建和组织测试?