Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way of only running unit tests in a single module using Eunit in Erlang/OTP?

Tags:

erlang

eunit

I have a number of modules with unit tests. Is there a way of only running unit tests in a single module?

This is what the relevant section of the module looks like:

-export([ ..... ])
-include_lib("eunit/include/eunit.hrl").
...
...
...
first_test() ->
  ...
  ...

second_test() ->
  ...
  ...
like image 891
mbsheikh Avatar asked Jan 16 '12 18:01

mbsheikh


3 Answers

Run all tests in the module/suite (as iuriza's answer):

rebar eunit suite=mod_name

Or you can also specify an individual test case (by function name):

rebar eunit tests=mod_name:test_name

References:

  • https://github.com/rebar/rebar/pull/118
  • https://github.com/rebar/rebar/pull/119
like image 61
joao cenoura Avatar answered Nov 09 '22 04:11

joao cenoura


eunit:test(yourmodule) or yourmodule:test() should work.

like image 5
Adam Lindberg Avatar answered Nov 09 '22 03:11

Adam Lindberg


If you're using rebar3 you can use the --module option per their Running Tests doc.

rebar3 eunit --module=your_module

If you have tons of modules, but only want to run tests for a few of them, you can separate the names with commas:

rebar3 eunit --module=first_module,second_module,third_module

The documentation has a lot of tips for limiting the tests run to a single application, file, etc.

like image 3
Grant Winney Avatar answered Nov 09 '22 03:11

Grant Winney