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

3.7k views Asked by At

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() ->
  ...
  ...
5

There are 5 answers

0
Adam Lindberg On BEST ANSWER

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

0
Kiko Fernandez On

Improving on the response from Adam Linberg, I did:

rebar3 as test shell

which makes possible to compile unit test files. Then you can type:

eunit:test(yourmodule)

or

yourmodule:test()
0
joao cenoura On

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

$ rebar3 eunit --module=mod1,mod2,mod3

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

$ rebar3 eunit --test=mod1:test1+test2,mod2:test1

References:

https://rebar3.org/docs/testing/eunit/

0
Grant Winney On

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.

0
iuriza On

You could also use:

rebar clean eunit suite=your_module