我正在运行应用程序,并且在交互式控制台中我尝试运行位于 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/