Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run eunit test from console using erl -noshell

Tags:

erlang

I wanted to run the following eunit test command from console

eunit:test([test_module, [verbose]).

I tried this, but seems not working 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.

Do you know how to pass not a simple arguments properly from console?

like image 521
allenhwkim Avatar asked Feb 22 '11 18:02

allenhwkim


3 Answers

Your parameters look wrong. This should work:

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

-s can only run functions without arguments by specifying the module and function name (for example init and stop to execute init:stop()).

You can also pass one list to a function of arity 1 like this:

-s foo bar a b c

would call

foo:bar([a,b,c])

All the parameters are passed as a list of atoms only (even when you try to use some other characters, such as numbers, they are converted to atoms).

So since you want to pass two params and not only atoms if you want to run eunit:test/2 you'd have to use -eval which takes a string containing Erlang code as an argument. All -eval and -s functions are executed sequentially in the order they are defined.

Also, make sure you have your test code in ./ebin as well (otherwise write -pa ebin test_ebin where test_ebin is where your test code is).

like image 122
Adam Lindberg Avatar answered Nov 05 '22 08:11

Adam Lindberg


You can also use rebar...

  • Get rebar by cd'ing to your project directory and typing the following:

    curl http://cloud.github.com/downloads/basho/rebar/rebar -o rebar

    chmod u+x rebar

  • Add the following to your module under test, right after last export:

    -ifdef(TEST).

    -include_lib("eunit/include/eunit.hrl").

    -endif.

  • Next, add your tests at the bottom of your module, wrapped in an ifdef like so:

    -ifdef(TEST).

    simple_test() ->

        ?assertNot(true).

    -endif.

  • Lastly, run rebar from your shell like so:

    ./rebar compile eunit

like image 2
Bill Barnhill Avatar answered Nov 05 '22 07:11

Bill Barnhill


you can try quote parameters instead of listing. erl -noshell -pa ./ebin -s eunit test "test_module verbose" -init stop

like image 1
osfist Avatar answered Nov 05 '22 07:11

osfist