使用erl -noshell从控制台运行eunit测试

all*_*kim 13 erlang

我想从控制台运行以下eunit test命令

eunit:test([test_module, [verbose]).
Run Code Online (Sandbox Code Playgroud)

我试过这个,但似乎没有工作erl -noshell -pa ./ebin -s eunit test test_module verbose -init stop

~/uid_server$erl -noshell -pa ./ebin -s eunit test test_module verbose -init stop
undefined
*** test module not found ***
::test_module

=======================================================
  Failed: 0.  Skipped: 0.  Passed: 0.
One or more tests were cancelled.
Run Code Online (Sandbox Code Playgroud)

你知道如何从控制台正确传递一个简单的参数吗?

Ada*_*erg 14

你的参数看起来不对.这应该工作:

erl -noshell -pa ebin -eval "eunit:test(test_module, [verbose])" -s init stop
Run Code Online (Sandbox Code Playgroud)

-s只能通过指定模块和函数名来运行没有参数的函数(例如init,stop执行init:stop()).

您还可以将一个列表传递给arity 1的函数,如下所示:

-s foo bar a b c
Run Code Online (Sandbox Code Playgroud)

会打电话

foo:bar([a,b,c])
Run Code Online (Sandbox Code Playgroud)

所有参数仅作为原子列表传递(即使您尝试使用其他一些字符,例如数字,它们也会转换为原子).

因此,既然你想要运行两个参数而不仅仅是原子,那么你eunit:test/2必须使用-eval包含Erlang代码的字符串作为参数.所有-eval-s函数按照它们的定义顺序执行.

另外,请确保您的测试代码也在./ebin中(否则请写入测试代码-pa ebin test_ebin所在test_ebin的位置).