Erlang 使用erl-noshell从控制台运行eunit测试
我想从控制台运行以下eunittest命令Erlang 使用erl-noshell从控制台运行eunit测试,erlang,Erlang,我想从控制台运行以下eunittest命令 eunit:test([test_module, [verbose]). 我试过这个,但似乎不起作用 erl-noshell-pa./ebin-s eunit测试模块详细信息-初始停止 ~/uid_server$erl -noshell -pa ./ebin -s eunit test test_module verbose -init stop undefined *** test module not found *** ::test_modul
eunit:test([test_module, [verbose]).
我试过这个,但似乎不起作用
erl-noshell-pa./ebin-s eunit测试模块详细信息-初始停止
~/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.
您知道如何正确地从控制台传递非简单参数吗?您可以尝试引用参数,而不是列出参数。
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.
erl -noshell -pa ebin -eval "eunit:test(test_module, [verbose])" -s init stop
-s
只能通过指定模块和函数名来运行没有参数的函数(例如init
和stop
执行init:stop()
)
您还可以将一个列表传递给arity 1的函数,如下所示:
-s foo bar a b c
会叫
foo:bar([a,b,c])
所有参数仅作为原子列表传递(即使您尝试使用一些其他字符,例如数字,它们也会转换为原子)
因此,如果要运行eunit:test/2
,您需要传递两个参数,而不仅仅是原子,那么必须使用-eval
,它将包含Erlang代码的字符串作为参数。所有-eval
和-s
函数都按照定义的顺序顺序执行
另外,确保您的测试代码也在./ebin中(否则写
-pa ebin test\u ebin
其中test\u ebin
是您的测试代码所在)。您也可以使用钢筋
- 通过将光盘刻录到项目目录并键入以下内容来获取钢筋:
curl-o钢筋
chmod u+x钢筋
- 在上次导出后立即将以下内容添加到您的测试模块中:
-ifdef(测试)。
-include_lib(“eunit/include/eunit.hrl”)。
-endif.
- 接下来,将测试添加到模块底部,并用ifdef包装,如下所示:
-ifdef(测试)。
simple\u test()->
?assertNot(true)。
-endif.
- 最后,从壳中运行钢筋,如下所示:
/eunit
eunit-module <module> src ebin -I deps
eunit模块src ebin-I deps
这可以做几件事:
- Arg#2是.erl所在的目录
- Arg#3是输出编译后的.beam的目录
- Arg#4++是要添加到代码路径的所有附加路径
- 使用-I指定其他代码路径以及在何处查找使用-include_lib引用的文件
test/0
功能,其中包含模块的所有测试
因此,如果您在同一模块中与源代码一起编写测试,您所要做的就是:
$ erl -noshell -run your_module test -run init stop
如果您在一个独立的、相关的模块中编写测试(您应该这样做),则必须指向该模块:
$ erl -noshell -run your_module_tests test -run init stop
所有这些都可以正常工作,但是测试不会按照OP的要求在详细模式下运行,但是将EUNIT
环境变量设置为verbose
可以很容易地解决这个问题
最终版本:
$ EUNIT=verbose erl -noshell -run your_module_tests test -run init stop
与Erlang和EUnit一起玩得开心